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

本文介绍了在Ubuntu 12.04上使用g++编译包含CPLEX库的C++程序时的配置步骤和遇到的链接错误。编译时需添加-I和-L选项指定头文件和库路径,并正确放置链接库顺序。遇到的链接错误主要与`__cxa_get_exception_ptr`等函数未定义有关,但作者的g++ 4.5.2版本并未出现此类问题。
摘要由CSDN通过智能技术生成

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


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


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


链接: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/li

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值