Ubuntu 12.04下用g++编译cplex实例程序,配置、出现的问题,解决办法

比如我要编译的实例程序为ilomipex1.cpp。


编译:g++ -I/home/stan/cplex/opl/include -DIL_STD ilomipex1.cpp -c; 


-DIL_STD选项的作用是为了兼容旧版本的#include 出现的问题。


链接:g++ -L/home/stan/cplex/concert/lib/x86_sles10_4.1/static_pic -L/home/stan/cplex/cplex/lib/x86_sles10_4.1/static_pic ilomipex1.o -o ilomipex1 -lilocplex -lcplex -lconcert -lm -lpthread。。


Ubuntu g++编译cplex,加载链接库的顺序必须为: -lilocplex -lcplex -lconcert,而且要放在命令的最后部分,否则会提示undefined reference to cplexsomething。这点非常非常重要。。


至于网上有些人说链接不通过是因为g++版本太高,我的g++版本是4.5.2,链接没有问题。。


我也试着去安装过低版本的g++,如g++-3.3,版本太低,链接失败,同样出现以下错误:

/home/stan/workspace/libilocplex.a(ilocplex.o): In function `IloCplexI::IloCplexI[in-charge](IloEnvI*, bool, cpxenv* (*)(char const*, int, char const* const*, int*), char const*, int, char const* const*)':
ilocplex.cpp:(.text+0x1ea22): undefined reference to `__cxa_get_exception_ptr'
/home/stan/workspace/libilocplex.a(ilocplex.o): In function `IloCplexI::IloCplexI[not-in-charge](IloEnvI*, bool, cpxenv* (*)(char const*, int, char const* const*, int*), char const*, int, char const* const*)':
ilocplex.cpp:(.text+0x2d0b6): undefined reference to `__cxa_get_exception_ptr'
/home/stan/workspace/libilocplex.a(ilodeflpextr.o): In function `IloDefaultLPExtractor::applySetNames(IloSetNameArrayChange const*, void**)':
ilodeflpextr.cpp:(.text+0x8e8): undefined reference to `__cxa_get_exception_ptr'
/home/stan/workspace/libilocplex.a(ilodeflpextr.o): In function `IloDefaultLPExtractor::doextractObj(IloObjectiveI const*, double&)':
ilodeflpextr.cpp:(.text+0x55b1): undefined reference to `__cxa_get_exception_ptr'
/home/stan/workspace/libconcert.a(iloalg.o): In function `IloAlgorithmI::apply(IloChange const&, IloExtractableI const*)':
iloalg.cpp:(.text+0x6637): undefined reference to `__cxa_get_exception_ptr'
/home/stan/workspace/libconcert.a(iloalg.o):iloalg.cpp:(.text+0x6760): more undefined references to `__cxa_get_exception_ptr' follow
/home/stan/workspace/libconcert.a(iloenv.o): In function `IloGetString(std::basic_ostringstream, std::allocator >&)':
iloenv.cpp:(.text+0xc96c): undefined reference to `std::basic_string, std::allocator >::_Rep::_S_empty_rep_storage'
iloenv.cpp:(.text+0xc9e9): undefined reference to `__gnu_cxx::__exchange_and_add(int volatile*, int)'
iloenv.cpp:(.text+0xca12): undefined reference to `std::basic_string, std::allocator >::_Rep::_S_empty_rep_storage'
iloenv.cpp:(.text+0xca27): undefined reference to `__gnu_cxx::__exchange_and_add(int volatile*, int)'
/home/stan/workspace/libconcert.a(iloenv.o): In function `IloEnvI::change(IloExtractableI const*, IloChange const&)':
iloenv.cpp:(.text+0xcb24): undefined reference to `__cxa_get_exception_ptr'
iloenv.cpp:(.text+0xcbb3): undefined reference to `__cxa_get_exception_ptr'
/home/stan/workspace/libconcert.a(iloenv.o): In function `IloEnvI::change(IloChange const&)':
iloenv.cpp:(.text+0xcdee): undefined reference to `__cxa_get_exception_ptr'
iloenv.cpp:(.text+0xce71): undefined reference to `__cxa_get_exception_ptr'
/home/stan/workspace/libconcert.a(iloenv.o):(.data.rel.ro._ZTV13IloPrivateBuf[vtable for IloPrivateBuf]+0x18): undefined reference to `std::basic_streambuf >::seekoff(long long, std::_Ios_Seekdir, std::_Ios_Openmode)'
/home/stan/workspace/libconcert.a(ilocollectionstruct.o): In function `IloOperatorException::getOperatorName() const':
ilocollectionstruct.cpp:(.text+0x158a): undefined reference to `std::basic_string, std::allocator >::_Rep::_S_empty_rep_storage'
ilocollectionstruct.cpp:(.text+0x15a3): undefined reference to `__gnu_cxx::__exchange_and_add(int volatile*, int)'
ilocollectionstruct.cpp:(.text+0x165f): undefined reference to `std::basic_string, std::allocator >::_Rep::_S_empty_rep_storage'
ilocollectionstruct.cpp:(.text+0x1678): undefined reference to `__gnu_cxx::__exchange_and_add(int volatile*, int)'
/home/stan/workspace/libconcert.a(ilocollectionstruct.o): In function `IloDataCollection::ImmutableException::getMessage() const':
ilocollectionstruct.cpp:(.text+0x184b): undefined reference to `std::basic_string, std::allocator >::_Rep::_S_empty_rep_storage'
ilocollectionstruct.cpp:(.text+0x1864): undefined reference to `__gnu_cxx::__exchange_and_add(int volatile*, int)'
ilocollectionstruct.cpp:(.text+0x1978): undefined reference to `std::basic_string, std::allocator >::_Rep::_S_empty_rep_storage'
ilocollectionstruct.cpp:(.text+0x1991): undefined reference to `__gnu_cxx::__exchange_and_add(int volatile*, int)'
/home/stan/workspace/libconcert.a(ilocollectionstruct.o): In function `IloIndexOutOfBoundsException::getMessage() const':
ilocollectionstruct.cpp:(.text+0x1b0f): undefined reference to `std::basic_string, std::allocator >::_Rep::_S_empty_rep_storage'
ilocollectionstruct.cpp:(.text+0x1b28): undefined reference to `__gnu_cxx::__exchange_and_add(int volatile*, int)'
ilocollectionstruct.cpp:(.text+0x1c3c): undefined reference to `std::basic_string, std::allocator >::_Rep::_S_empty_rep_storage'
ilocollectionstruct.cpp:(.text+0x1c55): undefined reference to `__gnu_cxx::__exchange_and_add(int volatile*, int)'
/home/stan/workspace/libconcert.a(ilocollectionstruct.o): In function `IloFirstLastElementNotFoundException::getMessage() const':
ilocollectionstruct.cpp:(.text+0x1dc0): undefined reference to `std::basic_string, std::allocator >::_Rep::_S_empty_rep_storage'
ilocollectionstruct.cpp:(.text+0x1dd9): undefined reference to `__gnu_cxx::__exchange_and_add(int volatile*, int)'
ilocollectionstruct.cpp:(.text+0x1e95): undefined reference to `std::basic_string, std::allocator >::_Rep::_S_empty_rep_storage'
ilocollectionstruct.cpp:(.text+0x1eae): undefined reference to `__gnu_cxx::__exchange_and_add(int volatile*, int)'
/home/stan/workspace/libconcert.a(ilocollectionstruct.o): In function `IloFirstLastElementNotFoundException::getOperatorName() const':
ilocollectionstruct.cpp:(.text+0x2098): undefined reference to `std::basic_string, std::allocator >::_Rep::_S_empty_rep_storage'
ilocollectionstruct.cpp:(.text+0x20b1): undefined reference to `__gnu_cxx::__exchange_and_add(int volatile*, int)'
ilocollectionstruct.cpp:(.text+0x216d): undefined reference to `std::basic_string, std::allocator >::_Rep::_S_empty_rep_storage'
ilocollectionstruct.cpp:(.text+0x2186): undefined reference to `__gnu_cxx::__exchange_and_add(int volatile*, int)'
/home/stan/workspace/libconcert.a(evaluator.o): In function `IloModelEvaluator::Unbound::getMessage() const':
evaluator.cpp:(.text+0x1767): undefined reference to `std::basic_string, std::allocator >::_Rep::_S_empty_rep_storage'
evaluator.cpp:(.text+0x1780): undefined reference to `__gnu_cxx::__exchange_and_add(int volatile*, int)'
evaluator.cpp:(.text+0x1894): undefined reference to `std::basic_string, std::allocator >::_Rep::_S_empty_rep_storage'
evaluator.cpp:(.text+0x18ad): undefined reference to `__gnu_cxx::__exchange_and_add(int volatile*, int)'
collect2: ld returned 1 exit status


成功的执行结果如下:


stan@stan-desktop:~/workspace$ ./ilomipex1
IBM ILOG CPLEX Optimization Studio Preview Edition good for 74 more days.
The CPLEX Optimizers will solve problems up to 500 variables and 500 constraints.
Tried aggregator 2 times.
MIP Presolve eliminated 0 rows and 1 columns.
Aggregator did 1 substitutions.
Reduced MIP has 2 rows, 3 columns, and 6 nonzeros.
Reduced MIP has 0 binaries, 1 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.00 sec. (0.01 ticks)
Found incumbent of value 34.000000 after 0.01 sec. (0.01 ticks)
Probing time = 0.00 sec. (0.00 ticks)
Tried aggregator 1 time.
Presolve time = 0.00 sec. (0.00 ticks)
Probing time = 0.00 sec. (0.00 ticks)
MIP emphasis: balance optimality and feasibility.
MIP search method: dynamic search.
Parallel mode: deterministic, using up to 2 threads.
Root relaxation solution time = 0.00 sec. (0.00 ticks)

        Nodes                                         Cuts/
   Node  Left     Objective  IInf  Best Integer    Best Bound    ItCnt     Gap

*     0+    0                           34.0000      163.0000        3  379.41%
      0     0      125.2083     1       34.0000      125.2083        3  268.26%
*     0+    0                          122.5000      125.2083        3    2.21%
      0     0        cutoff            122.5000                      3    0.00%
Elapsed time = 0.03 sec. (0.04 ticks, tree = 0.00 MB, solutions = 2)

Root node processing (before b&c):
  Real time             =    0.03 sec. (0.02 ticks)
Parallel b&c, 2 threads:
  Real time             =    0.00 sec. (0.00 ticks)
  Sync time (average)   =    0.00 sec.
  Wait time (average)   =    0.00 sec.
                          ------------
Total (root+branch&cut) =    0.03 sec. (0.02 ticks)
Solution status = Optimal
Solution value  = 122.5
Values        = [40, 10.5, 19.5, 3]
Slacks        = [0, 2, 0]
Default variable names x1, x2 ... being created.
Default row names c1, c2 ... being created.

你可能感兴趣的:(C/C++,杂)