编译Gurobi示例代码时的链接器错误

时间:2019-12-10 18:13:29

标签: c++ compiler-errors compilation linker gurobi

我正在尝试使用{p> 3编译Gurobi示例

g++ dense_cpp.cpp -I $GUROBI_HOME/include

其中$GUROBI_HOME是我的Gurobi安装目录的主目录。我收到以下错误:

Undefined symbols for architecture x86_64:
  "GRBLinExpr::GRBLinExpr(double)", referenced from:
      dense_optimize(GRBEnv*, int, int, double*, double*, double*, char*, double*, double*, double*, char*, double*, double*) in dense_cpp-1ed621.o
  "GRBLinExpr::operator+=(GRBLinExpr const&)", referenced from:
      dense_optimize(GRBEnv*, int, int, double*, double*, double*, char*, double*, double*, double*, char*, double*, double*) in dense_cpp-1ed621.o
[...]
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

有人知道如何解决此问题吗?

1 个答案:

答案 0 :(得分:0)

正确的命令是

g++ dense_cpp.cpp -o dense -I $GUROBI_HOME/include -L $GUROBI_HOME/lib -lgurobi_c++ -lgurobi90

我的~/.bash_profile包含

export GUROBI_HOME="/Library/gurobi900/mac64"
export PATH="${PATH}:${GUROBI_HOME}/bin"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${GUROBI_HOME}/lib"