Originally posted by: EdKlotz
>
> Hi,
>
> I am just getting started with CPLEX, and have a very basic question that I was hoping someone could give me some advice on: I am having trouble compiling a very simple program. I am listing the barebones code (called test.c) below:
>
> #include<stdio.h>
> #include "C:\Program Files\IBM\ILOG\CPLEX_Studio_Preview125\cplex\include\ilcplex\cpxconst.h"
> #include "C:\Program Files\IBM\ILOG\CPLEX_Studio_Preview125\cplex\include\ilcplex\cplex.h"
> #include "C:\Program Files\IBM\ILOG\CPLEX_Studio_Preview125\cplex\include\ilcplex\cplexremote.h"
> #include "C:\Program Files\IBM\ILOG\CPLEX_Studio_Preview125\cplex\include\ilcplex\cplexremotemaster.h"
>
> main()
> {
>
> int status = 0;
> CPXENVptr env = NULL;
>
> env = CPXopenCPLEX (&status);
>
> }
>
>
> I compiled this with: gcc -I"c:\Program Files\IBM\ILOG\CPLEX_Studio_Preview125\cplex\include" test.c -L"c:\Program Files\IBM\ILOG\CPLEX_Studio_Preview125\cplex\lib"
>
> I get the error: undefined reference to `_imp__CPXopenCPLEX@4' collect2: ld returned 1 exit status
>
> If I comment out the CPXopenCPLEX line, the code compiles.
>
> Am I missing an include file? Am I not linking an appropriate library? Am I supposed to include a particular directory on my path? I know that it is probably something very simple that I am overlooking, but any suggestions on how to proceed would be appreciated.
>
> Thanks
If you were missing an include file, you probably would have encountered an error
message at compile time rather than at link time as we see above.
Part of the issue here is that gcc is an unsupported compiler on Windows. It is
supported on Linux. I think you have two options.
1) If you have access to Microsoft Visual Studio, just use that; it is the officially supported compiler. Your CPLEX distribution comes with various
project files for this compiler, making compiling and linking much easier.
Just use one of the projects to confirm that one of the example programs
provided compiles and links successfully, then make a copy of the project and
modify it to correspond to your program.
2) It may be possible to get gcc for Windows to work properly. I think the problem
is that you have specified the directory containing the import library but you haven't
specified the import library name. The import library name is cplex125.lib. I'm not
familiar with gcc under Windows, but I suspect you need to add an -lcplex125 to your
link statement. Also, make sure you have specified the correct argument to the
-L option; the lib directory typically contains subdirectories that contain the
actual import libraries to which you need to link.
I recommend option 1 if possible. Otherwise, I hope the above suggestions help.
For a fairly general discussion of CPLEX and linker errors, take a look at the technote at
http://www-01.ibm.com/support/docview.wss?uid=swg21399926#CPLEXOptimizers#DecisionOptimization