coin-or / Clp

COIN-OR Linear Programming Solver
Other
392 stars 82 forks source link

Conan 2.x integration #275

Closed matheusdiogenesandrade closed 1 year ago

matheusdiogenesandrade commented 1 year ago

Environment

Current structure

The MWE can be found here.

[settings]
os=Linux
arch=x86_64
compiler=gcc
compiler.version=11
compiler.cppstd=20
compiler.libcxx=libstdc++11
build_type=Release

[options]

[conf]
[requires]
coin-utils/2.11.6
coin-osi/0.108.7
coin-clp/1.17.7

[generators]
CMakeDeps
CMakeToolchain
cmake_minimum_required(VERSION 3.23)
project(CoinConanTest)

##### SETs
set (CMAKE_BUILD_TYPE Release) 
set (CMAKE_CXX_STANDARD 20)
set (BUILD_SHARED_LIBS On)

##### Additional packages 

find_package (coin-utils REQUIRED)
find_package (coin-osi REQUIRED)
find_package (coin-clp REQUIRED)

##### Include Dirs 

include_directories( SYSTEM includes "${PROJECT_BINARY_DIR}" )

##### Compile options 

add_compile_options(-Wall
    -DIL_STD
    -Wfatal-errors
    -pedantic
    -fopenmp
    -DDEBUG
    -fdiagnostics-color=always
    #    -Wall
    -lz
    -std=c++20
    #
    -lm 
    -lpthread 
    -ldl
    -Wno-sign-compare)

file(GLOB_RECURSE SOURCES "src/*.cpp")

add_executable( main ${SOURCES} )

target_link_libraries(main pthread m dl)
#include "coin/OsiClpSolverInterface.hpp"

int main (int argc, const char *argv[])
{
    OsiClpSolverInterface model;
    return 0;
}

Process

mkdir build
conan install . --profile conanprofile.txt --output-folder=build --build=missing
cd build
cmake .. --preset conan-release
make

Expected result

[ 50%] Building CXX object CMakeFiles/main.dir/src/main.cpp.o
[100%] Linking CXX executable main
[100%] Built target main

Actual result

[ 50%] Linking CXX executable main
/usr/bin/ld: CMakeFiles/main.dir/src/main.cpp.o: in the function `main':
main.cpp:(.text.startup+0x56): reference to `OsiClpSolverInterface::OsiClpSolverInterface()' not defined
/usr/bin/ld: main.cpp:(.text.startup+0x5e): reference to `OsiClpSolverInterface::~OsiClpSolverInterface()' not defined
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/main.dir/build.make:97: main] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/main.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

Goal

Fix the compilation.

Guess

Probably we have to set the target_link_libraries accordingly.

Thanks and regards.

matheusdiogenesandrade commented 1 year ago

Thanks for the attention. I already managed this. Suffices to add the following target link libs:

target_link_libraries(main 
  coin-clp::coin-clp
  coin-osi::coin-osi
  pthread m dl
)

However, it seems that the CBC still has no integration with Conan 2.x.