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:
#include <lsndp_heuristic/ModelFlow.h> ModelFlow::ModelFlow(HeurGraph graph, Instance::ptr instance) : graph(graph), instance(instance), env(), model(env), cplex(model) { }
ModelFlow.h:
class ModelFlow { private: IloEnv env; IloModel model; IloCplex cplex; HeurGraph graph; Instance::ptr instance; public: ModelFlow(HeurGraph graph, Instance::ptr Instance); ModelFlow() = default; ~ModelFlow() = default; };
The output with the error message when I run “make” is this (“format” by me):
g++ -g -std=c++17 -D IL_STD -I LinerNetworks/src -I /usr/include/boost -I /opt/ibm/ILOG/CPLEX_Studio1210/concert/include -I /opt/ibm/ILOG/CPLEX_Studio1210/cplex/include -L /opt/ibm/ILOG/CPLEX_Studio1210/concert/lib/x86-64_linux/static_pic -L /opt/ibm/ILOG/CPLEX_Studio1210/cplex/lib/x86-64_linux/static_pic LinerNetworks/obj/shared/SailingLeg.o LinerNetworks/obj/shared/Ship.o LinerNetworks/obj/shared/Port.o LinerNetworks/obj/shared/ShipRoute.o LinerNetworks/obj/shared/Instance.o LinerNetworks/obj/new_liner_networks/graph/Arc.o LinerNetworks/obj/new_liner_networks/graph/Node.o LinerNetworks/obj/new_liner_networks/graph/GraphFactory.o LinerNetworks/obj/lsndp_heuristic/FlowAlgorithm.o LinerNetworks/obj/lsndp_heuristic/Main.o LinerNetworks/obj/lsndp_heuristic/MoveShip.o LinerNetworks/obj/lsndp_heuristic/AddPort.o LinerNetworks/obj/lsndp_heuristic/Neighborhood.o LinerNetworks/obj/lsndp_heuristic/RemovePort.o LinerNetworks/obj/lsndp_heuristic/ModelFlow.o LinerNetworks/obj/lsndp_heuristic/Misc.o LinerNetworks/obj/lsndp_heuristic/Solution.o LinerNetworks/obj/lsndp_heuristic/graph/ArcHeur.o LinerNetworks/obj/lsndp_heuristic/graph/NodeHeur.o LinerNetworks/obj/lsndp_heuristic/graph/GraphFactoryHeur.o -o heuristic /usr/bin/ld: LinerNetworks/obj/lsndp_heuristic/ModelFlow.o: in function `ModelFlow::ModelFlow(boost::adjacency_list<boost::vecS, boost::listS, boost::bidirectionalS, VertexProperty, EdgeProperty, boost::no_property, boost::listS>, std::shared_ptr<Instance>)': /home/nemanja/Projects/phd/lsndp_heuristic/LinerNetworks/src/lsndp_heuristic/ModelFlow.cpp:4: undefined reference to `IloEnv::IloEnv()' /usr/bin/ld: /home/nemanja/Projects/phd/lsndp_heuristic/LinerNetworks/src/lsndp_heuristic/ModelFlow.cpp:4: undefined reference to `IloModel::IloModel(IloEnv, char const*)' /usr/bin/ld: /home/nemanja/Projects/phd/lsndp_heuristic/LinerNetworks/src/lsndp_heuristic/ModelFlow.cpp:4: undefined reference to `IloCplex::IloCplex(IloModel)' collect2: error: ld returned 1 exit status make: *** [makefile:26: all] Error 1
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
:
-lconcert -lilocplex -lcplex -lm -lpthread -ldl
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.