Hello.
I am trying to setup a C++ project with CMake for the compilation. However, I am having some issues when linking the Cplex CPO. For linking the Cplex dependecies, I used the FindCPLEX.cmake.
The complete setup can be seen in the repository, where I try to compile the cpoptimizer/examples/src/cpp/alloc.cpp. Since I am not sure if I can share this file, I left an empty src/main.cpp in the repository, so if someone wants to reproduce the experiment, you will have to ctrl+c/ctrl+v the content from your cplex folder.
Below follows my CMakeLists.txt:
cmake_minimum_required(VERSION 3.23)
project(CplexCP)
##### SETs
set (Project_PATH "${PROJECT_SOURCE_DIR}")
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/support/cmake)
set (CMAKE_BUILD_TYPE Release)
set (CMAKE_CXX_STANDARD 20)
set (BUILD_SHARED_LIBS On)
##### Packages
find_package (CPLEX)
##### Include Dirs
link_directories(${CPLEX_CP_LIBRARY})
include_directories(
SYSTEM
includes
"${PROJECT_BINARY_DIR}"
"${CPLEX_CONCERT_INCLUDE_DIR}"
"${CPLEX_ILOCPLEX_INCLUDE_DIR}"
"${CPLEX_CP_INCLUDE_DIR}"
)
##### Compile options
add_compile_options(-Wall
#
-DIL_STD
-Wfatal-errors
-pedantic
-fopenmp
-DDEBUG
-fdiagnostics-color=always
-lz
-std=c++20
# CPLEX
-lconcert
-lilocplex
-lcplex
-lcplex-cp
-lcplex-concert
-lcplex-library
#
-lm
-lpthread
-ldl
-Wno-sign-compare
)
file(GLOB_RECURSE SOURCES "src/*.cpp")
add_executable(
main
${SOURCES}
)
target_link_libraries(
main
${CPLEX_CONCERT_LIBRARY}
${CPLEX_ILOCPLEX_LIBRARY}
${CPLEX_LIBRARY}
${CPLEX_CP_LIBRARY}
${CPLEX_CP_LIBRARY_DEBUG}
pthread
m
dl
)
The cmake command works just fine, but the make, results in the following. The complete log can be seen here.
/usr/bin/ld: /opt/ibm/ILOG/CPLEX_Studio2211/cpoptimizer/lib/x86-64_linux/static_pic/libcp.a(cpengine.o): in the function `IlcCPEngineI::IlcCPEngineI(IlcCPI*, IlcAllocator*, long, IlcCPOManagerI*)':
cpengine.cpp:(.text+0x8ae6): reference to `CPXEclocksync' not defined
...
/usr/bin/ld: /opt/ibm/ILOG/CPLEX_Studio2211/cpoptimizer/lib/x86-64_linux/static_pic/libcp.a(linoptcplex.o): in the function `IlcLinOptCplex::parameterConfiguration(long, double)':
linoptcplex.cpp:(.text+0x5ad1): reference to `CPXsetintparam' not defined
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/main.dir/build.make:102: main] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/main.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
What am I missing in my CMakeLists.txt?
Thanks and regards.
------------------------------
Matheus Andrade
------------------------------