Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Very basic compiling question

    Posted 02/13/13 02:10 PM

    Originally posted by: SystemAdmin


    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
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Very basic compiling question

    Posted 02/13/13 09:06 PM

    Originally posted by: EdKlotz


    > YPT9_Marshall_Sussman wrote:
    > 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


  • 3.  Re: Very basic compiling question

    Posted 02/14/13 02:12 AM

    Originally posted by: SystemAdmin


    It seems like you are missing the CPLEX library on your command line. -L only tells the compiler where to find the libs, it does not instruct it which libs to use. So need to add something like -lcplex or -lcplex125, or just specify the absolute path to the library. Moreover, the argument to -L is not correct. You need to have something like this instead: -L"c:\Program Files\IBM\ILOG\CPLEX_Studio_Preview125\cplex\lib\x86_windows_vs2008\stat_mta" (depending on the lib you want to use for linking).
    Like Ed said, it seems like you are using a compiler that is not officially supported, so there may be further problems after you fixed the linking step.
    I have never tried using gcc on Windows. I don't know whether linking against the cplex125.lib is correct. Maybe you need to link against cplex125.dll instead?
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Very basic compiling question

    Posted 02/14/13 02:17 PM

    Originally posted by: EdKlotz


    > dju358 wrote:
    > It seems like you are missing the CPLEX library on your command line. -L only tells the compiler where to find the libs, it does not instruct it which libs to use. So need to add something like -lcplex or -lcplex125, or just specify the absolute path to the library. Moreover, the argument to -L is not correct. You need to have something like this instead: -L"c:\Program Files\IBM\ILOG\CPLEX_Studio_Preview125\cplex\lib\x86_windows_vs2008\stat_mta" (depending on the lib you want to use for linking).
    > Like Ed said, it seems like you are using a compiler that is not officially supported, so there may be further problems after you fixed the linking step.
    > I have never tried using gcc on Windows. I don't know whether linking against the cplex125.lib is correct. Maybe you need to link against cplex125.dll instead?
    Typically you want to link against the import library. However, because gcc is
    unsupported, there is some chance that it will not be compatible with the import
    library created by Microsoft Visual C/C++. In that case, hopefully gcc comes with
    some sort of utility that will create a compatible import library from the DLL.
    Users of Borland C/C++ used Borland's implib utility to do that; something analogous
    may be needed here.

    I don't think you can link directly to a DLL. You can access the DLL directly by
    using the system loadlibrary function, then access pointers to the CPLEX functions
    and call them. That would require some additional coding, essentially of a wrapper
    for the function pointers. I don't really recommend that approach, as I expect
    the time spent would exceed any cost of obtaining Microsoft Visual Studio.
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Very basic compiling question

    Posted 02/14/13 02:50 PM

    Originally posted by: T_O


    First of all: gcc/g++ on Windows works fine with the C API, but not with the Concert, because there is no Concert version that is compiled with g++ on Windows. (Maybe, IBM could release an unofficial one? Or "just" make Concert open source so one can compile it with his favourite compiler.)

    As everyone mentioned, your main problem is due to a missing "-lcplex125".

    You can link to the Visual Studio .lib file, but for some reason, I created my own import library:
    gendef.exe cplex125.dll
    dlltool --output-lib libcplex125.a --input-def cplex125.def --dllname=cplex125.dll
    

    (Actually, I am using MinGW64 to compile 64-bit binaries on Windows 7 64-bit.)

    Here are some other tips:
    • The inclusion of cplex.h should be sufficient, you should not need the other includes.
    • I would do the following:
    #include <ilcplex/cplex.h>
    

    and add C:\Program Files\IBM\ILOG\CPLEX_Studio_Preview125\cplex\include to the include paths.
    • You should also remember that you have to use the 32-bit version of CPLEX if you compile a 32-bit binary and that you have to use the 64-bit version of CPLEX if you compile a 64-bit binary. (In the latter case, I had to definde _LP64.)

    Best regards,
    Thomas
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Very basic compiling question

    Posted 02/16/13 12:49 AM

    Originally posted by: SystemAdmin


    Thanks a lot for all your suggestions. I will give them a try!
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Very basic compiling question

    Posted 02/20/13 01:37 PM

    Originally posted by: SystemAdmin


    Hi,

    I decided to take the easy way out, and just use Visual Studio. It worked!

    Thanks very much for the help!

    Marshall
    #CPLEXOptimizers
    #DecisionOptimization