0

I am trying to compile OR-tools using a binary package that I downloaded and whose tests are running fine. Also the framework here https://github.com/or-tools/cmake_or-tools compiles ok on my system but it insists on using AppleClang which does not support OpenMP.

When building a DIY CMakeLists.txt, how can I link properly and compile against or tools?

I am happy to generate more linker output.

Thank you all!

My CMakeLists.txt is:

cmake_minimum_required(VERSION 3.21)
project(weights)

# Build OR-tools dependencies.
set(BUILD_DEPS ON)

# Disable SCIP solver.
set(USE_SCIP OFF)

set(CMAKE_CXX_STANDARD 17)
if(UNIX)
    option(BUILD_SHARED_LIBS "Build shared libraries(.so)." ON)
else()
    # only support for static build on Windows.
    set(BUILD_SHARED_LIBS OFF)
endif()

if(BUILD_SHARED_LIBS)
    set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()

find_package(Eigen3 REQUIRED)
find_package(OpenMP REQUIRED)

find_package (ortools PATHS "/Users/jerome/CLionProjects/glop" NO_DEFAULT_PATH REQUIRED CONFIG)
add_executable(weights main.cpp)


set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -gdwarf-3")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -gdwarf-3")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH True)


target_include_directories(weights PRIVATE ${EIGEN3_INCLUDE_DIR})
target_include_directories(weights PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_features(weights PUBLIC
        $<IF:$<CXX_COMPILER_ID:MSVC>,cxx_std_20,cxx_std_17>)

target_link_libraries(weights OpenMP::OpenMP_CXX ortools::ortools)

I simply get inexplicable linker errors such as

"__ZN19operations_research8MPSolver10MakeNumVarEddRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", referenced from:
      __ZN19operations_research12BasicExampleEv in main.cpp.o
  • 1
    Does this resolve your problem; [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) ? – Jesper Juhl Apr 27 '23 at 17:40
  • Hi @JesperJuhl sadly not. The library against which I am linking is a pretty involved one and somehow one set of Cmake instructions sets it up correctly, while my self-written CMakeLists.txt fails at doing so. Ideally, I am looking for a Cmake command I am missing. – KeynesCoeFen Apr 27 '23 at 18:12
  • 1
    "_but it insists on using AppleClang_" in what way? Is that a documented restriction? Or is it just some behaviour that you don't know how to change? How are you trying to change it, and what do you observe as a result of each different attempt? – starball Apr 27 '23 at 22:00
  • Meant that it works well with Apple clang, will investigate more and report back. – KeynesCoeFen Apr 27 '23 at 22:42

1 Answers1

3

I really want to avoid becoming DenverCoder9 so I am posting an answer to what helped me.

  1. Get a more informative error message:

When forcing a compilation with GCC, I received a more informative error message about a version incompatibility between a dynamic library that was being linked to and my OS version (13).

  1. Investigate the linking issues.

Per this answer here, the following line in my CMakeLists.txt did the trick: SET(CMAKE_OSX_DEPLOYMENT_TARGET 13.0)

This specification is for Mac OS 13.0. It may change in the future.

Now, it's all working and I hope this answer may help someone else.