Skip to content
Advertisement

How can I fix this “undefined reference” error using G++ and CPLEX?

I apologize if this is not the correct community to ask this on, in that case, please tell me which one is. I tried some IBM forums but I get a (general?) error when I try to start a thread there. I am decently experienced with CPLEX (on Windows, with visual studio c++), but when I try to compile the following simple empty model with g++ on Ubuntu I get an error. The code I’m working on is this: ModelFlow.cpp:

JavaScript

ModelFlow.h:

JavaScript

The output with the error message when I run “make” is this (“format” by me):

JavaScript

I checked the folders /opt/…/concert/include and /opt/…/cplex/include and they do contain files iloenv.h, ilocplex.h, ilocplexi.h and ilomodel.h. Specifically for this reason, I have no clue what I am doing wrong. If I need to provide more information, please let me know. Apologies in advance for any beginner issues in this post, this is my first post. May Covid-19 skip you.

Advertisement

Answer

It seems you are missing the required libraries for the linker. You only specified -L options to tell the linker where to find the libraries. You did not add -l options to tell which libraries to link. Try adding this before -o heuristic:

JavaScript

In general, to find the right flags for compilation you can go to INSTALLDIR/cplex/examples/x86-64_linux/static_pic and run make blend. This shows the compilation and linker commands and you can pick up the required flags from there.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement