0

I'm trying to compile this Gurobi example using

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

where $GUROBI_HOME is the home directory of my Gurobi installation. I'm getting the following errors:

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)

Does anyone know how to fix this?

user76284
  • 1,037
  • 12
  • 25
  • 2
    Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Richard Critten Dec 10 '19 at 18:16
  • ***g++ dense_cpp.cpp -I $GUROBI_HOME/include*** seems like you missed linking to a library. – drescherjm Dec 10 '19 at 18:27

1 Answers1

0

The correct command is

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

My ~/.bash_profile contains

export GUROBI_HOME="/Library/gurobi900/mac64"
export PATH="${PATH}:${GUROBI_HOME}/bin"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${GUROBI_HOME}/lib"
user76284
  • 1,037
  • 12
  • 25