Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  C++ and Cplex: Trouble linking files

    Posted 10/22/15 01:10 PM

    Originally posted by: CarlosBF


    Hi,

    I've been trying to run model, using C++ and CPLEX,   and can't find what I'm doing wrong. It compiles fine, but linking doesn't work, and gives me the errors that appear in the attached file.

    I really can't find the error, any help will be appreciated.

    Thanks. 

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: C++ and Cplex: Trouble linking files

    Posted 10/22/15 01:26 PM

    Originally posted by: Laci Ladanyi


    On linux the order in which you list the libraries to be linked with matters. The linker goes from left to right, examining every library trying to find symbols that it has already encountered but have not yet been defined. You have the order as " -lstdc++ -lcplex -lilocplex -lconcert -lcp -lcplexdistmip -lm -lpthread", and end up with a number of undefined symbols. Let's pick one, say, CPXLgetpnorms. In this case libcplex.a does define CPXLgetpnorms, but when -lcplex is encountered CPXLgetpnorms was not yet needed, so it does not get picked up. When later on CPXLgetpnorms is needed by a function in another library it's too late, the linker will not go back. So to find all symbols all you need to do is to properly reorder the libraries. I believe it'd be "-lconcert -lilocplex -lcplexdistmip -lcplex -lm -lpthread -ldl" (as it is in the cplex/examples/x86-64_linux/static_pic/Makefile.distmip). I don't think you need to specify -lstdc++, that will be used automatically by g++ (oh yes, to link a code that uses C++ you should really use g++ and not gcc to make sure everything is picked up correctly).

     

    --Laci


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: C++ and Cplex: Trouble linking files

    Posted 10/22/15 02:14 PM

    Originally posted by: CarlosBF


    Thanks!, finally the correct order was  "-lcp -lconcert  -lilocplex -lcplex   -lm -lpthread -ldl". 


    #CPLEXOptimizers
    #DecisionOptimization