Search code examples
c++c++11makefileclioncplex

Install cplexAPI C++ library in CLion C++11 and gets error with ld.exe


I'm trying to use cplexAPI C++ in a CLion project with C++11 on Windows 10. I have looked at several posts related to this question (e.g. config CMakeLists.txt, install MinG64) and I have managed to configure my CMakeLists.txt in the following way:

cmake_minimum_required(VERSION 3.15)
project(VRP_PRP)

add_executable(VRP_PRP main.cpp held-karp.h held-karp.cpp)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}  -m64 -O -fPIC -fexceptions -DNDEBUG -DIL_STD -std=c++11")

include_directories(/biblio/cplex/include/)
include_directories(/biblio/cplex/include/ilcplex)
include_directories(/biblio/concert/include)
include_directories(/biblio/concert/include/ilconcert)

target_link_libraries(VRP_PRP PUBLIC /biblio/cplex/lib/x64_windows_msvc14/stat_mda/cplex12100.lib)
target_link_libraries(VRP_PRP PUBLIC /biblio/cplex/lib/x64_windows_msvc14/stat_mda/ilocplex.lib)
target_link_libraries(VRP_PRP PUBLIC /biblio/concert/lib/x64_windows_msvc14/stat_mda/concert.lib)

target_link_libraries(VRP_PRP PUBLIC "-lilocplex -lconcert -lcplex -lm -lpthread")

it happens that when building my project it throws the following errors:

[ 33%] Linking CXX executable VRP_PRP.exe
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lilocplex
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lconcert
C:/PROGRA~1/MINGW-~1/X86_64~1.0-P/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lcplex
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[2]: *** [CMakeFiles\VRP_PRP.dir\build.make:105: VRP_PRP.exe] Error 1
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:75: CMakeFiles/VRP_PRP.dir/all] Error 2
mingw32-make.exe: *** [Makefile:83: all] Error 2

and by including the libraries (#include <ilcplex/ilocplex.h>) in my main.cpp it can't find them.

I have tried using 2 ways to link libraries in my CMakeLists.txt:

a) #set (target_link_options "-lilocplex -lconcert -lcplex -lm -lpthread -framework CoreFoundation -framework IOKit -std=c++11")

b) #target_link_libraries(VRP_PRP PUBLIC "-lilocplex -lconcert -lcplex -lm -lpthread")

Any help or idea will be appreciated.

Thanks.


Solution

  • My solution.

    I installed Visual Studio 2017 Community together with CPLEX 12.9 Academic Version, then I opened the examples which is in:

    C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\examples

    and they already come with the configuration done.