0

I would like to execute a working project with CLion.
So I was trying to emulate the Makefile through cmake but I'm not very good in it. I am sure that the error is inside cmake since the project is working with regular Makefile. Unfortunately, I cannot show a lot information on the project. I hope what I will show would be enough to receive your help.

The project directory structure ( without showing the files ) is shown in the following:

.
├── CMakeLists.txt
├── makefile
├── include
│   ├── data
│   ├── io
│   ├── learning
│   ├── metric
│   ├── scoring
│   └── io
└── src
    ├── data
    ├── io
    ├── learning
    ├── metric
    ├── scoring
    ├── utils
    └── main.cc

./CMakeLists.txt

cmake_minimum_required(VERSION 3.3)
project(Project)
set(DCMAKE_CXX_COMPILER "g++-5")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(Boost 1.57.0 COMPONENTS program_options system filesystem REQUIRED)
find_package(OpenMP)
if (OPENMP_FOUND)
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
include_directories(${Boost_INCLUDE_DIRS})
include_directories("include")
include_directories("src")
add_executable(Project src/main.cc)
target_link_libraries(Project ${Boost_LIBRARIES})

The project compiles without error, but fails during linking.
Part of the error is reported in the following:

[ 50%] Linking CXX executable Project
CMakeFiles/Project.dir/src/main.cc.o: in function "metric::ir::ir_metric_factory(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned int)":
./include/metric/metricfactory.h:47: undefined reference to "metric::ir::Dcg::NAME_[abi:cxx11]"
./include/metric/metricfactory.h:49: undefined reference to "metric::ir::Ndcg::NAME_[abi:cxx11]"
./include/metric/metricfactory.h:51: undefined reference to "metric::ir::Tndcg::NAME_[abi:cxx11]"
./include/metric/metricfactory.h:53: undefined reference to "metric::ir::Map::NAME_[abi:cxx11]"
CMakeFiles/Project.dir/src/main.cc.o: in function "main":
./src/main.cc:130: undefined reference to "learning::forests::LambdaMart::NAME_[abi:cxx11]"
./src/main.cc:170: undefined reference to "learning::forests::Mart::NAME_[abi:cxx11]"
./src/main.cc:171: undefined reference to "learning::forests::LambdaMart::NAME_[abi:cxx11]"
./src/main.cc:172: undefined reference to "learning::forests::ObliviousMart::NAME_[abi:cxx11]"
./src/main.cc:173: undefined reference to "learning::forests::ObliviousLambdaMart::NAME_[abi:cxx11]"
./src/main.cc:174: undefined reference to "learning::linear::CoordinateAscent::NAME_[abi:cxx11]"
./src/main.cc:175: undefined reference to "learning::forests::Project::NAME_[abi:cxx11]"
./src/main.cc:176: undefined reference to "learning::CustomLTR::NAME_[abi:cxx11]"
./src/main.cc:181: undefined reference to "metric::ir::Dcg::NAME_[abi:cxx11]"
./src/main.cc:182: undefined reference to "metric::ir::Ndcg::NAME_[abi:cxx11]"
./src/main.cc:183: undefined reference to "metric::ir::Tndcg::NAME_[abi:cxx11]"
./src/main.cc:184: undefined reference to "metric::ir::Map::NAME_[abi:cxx11]"
./src/main.cc:247: undefined reference to "metric::ir::Dcg::NAME_[abi:cxx11]"
./src/main.cc:248: undefined reference to "metric::ir::Ndcg::NAME_[abi:cxx11]"
./src/main.cc:249: undefined reference to "metric::ir::Tndcg::NAME_[abi:cxx11]"
./src/main.cc:250: undefined reference to "metric::ir::Map::NAME_[abi:cxx11]"
./src/main.cc:319: undefined reference to "learning::forests::LambdaMart::NAME_[abi:cxx11]"
./src/main.cc:324: undefined reference to "learning::forests::Mart::NAME_[abi:cxx11]"
./src/main.cc:329: undefined reference to "learning::forests::ObliviousMart::NAME_[abi:cxx11]"
./src/main.cc:334: undefined reference to "learning::forests::ObliviousLambdaMart::NAME_[abi:cxx11]"
./src/main.cc:339: undefined reference to "learning::linear::CoordinateAscent::NAME_[abi:cxx11]"
./src/main.cc:346: undefined reference to "learning::linear::CoordinateAscent::CoordinateAscent(unsigned int, double, double, unsigned int, unsigned int)"
./src/main.cc:347: undefined reference to "learning::forests::Project::NAME_[abi:cxx11]"
./src/main.cc:351: undefined reference to "learning::CustomLTR::NAME_[abi:cxx11]"
./src/main.cc:352: undefined reference to "learning::CustomLTR::CustomLTR()"
( other errors lines )
collect2: error: ld returned 1 exit status
make[2]: *** [Project] Error 1
make[1]: *** [CMakeFiles/Project.dir/all] Error 2
make: *** [all] Error 2
Draxent
  • 500
  • 1
  • 6
  • 14
  • 1
    Looks like functions `learning::` namespace are implemented somewhere under `src/learning`, so you need to compile those sources too. Similar for other namespaces (e.g. `metric::`). – Tsyvarev Apr 27 '16 at 08:22
  • sorry, how can I compile them ? can you do an example, please ? – Draxent Apr 27 '16 at 08:37
  • 1
    Just enumerate all sources in `add_executable()` command, after `src/main.cc`. – Tsyvarev Apr 27 '16 at 08:46
  • But I did `include_directories(src)`, is it not the same things ? Does exist a shorter way to do that ? Instead of inserting in `add_executable()` all my source files that are almost one hundred. – Draxent Apr 27 '16 at 08:56
  • 1
    You definitely need some tutorial about CMake. Command `include_directories()` doesn't add sources for compile, it adds directory for **search headers**. Command [file(GLOB)](https://cmake.org/cmake/help/v3.0/command/file.html) can be used for collect source files in directory. – Tsyvarev Apr 27 '16 at 09:11
  • Oh, you are not the only one who misunderstand intention of `include_directories` command. See also [that question](http://stackoverflow.com/questions/36885921/including-directories-in-clion). – Tsyvarev Apr 27 '16 at 11:20

1 Answers1

0

Ok, I solve it thanks to the help of Tsyvarev.
./CMakeLists.txt

cmake_minimum_required(VERSION 3.3)
project(Project)
set(DCMAKE_CXX_COMPILER "g++-5")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(Boost 1.57.0 COMPONENTS program_options system filesystem REQUIRED)
find_package(OpenMP)
if (OPENMP_FOUND)
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
include_directories(${Boost_INCLUDE_DIRS})
include_directories("include")
file(GLOB_RECURSE SOURCES src/*.cc) #*/
add_executable(Project ${SOURCES})
target_link_libraries(Project ${Boost_LIBRARIES})

where I used file(GLOB_RECURSE SOURCES src/*.cc) to add sources instead of include_directories("src").

Community
  • 1
  • 1
Draxent
  • 500
  • 1
  • 6
  • 14