I use CMake 3.5.2. When trying to build my C++ code I get the following error:
[100%] Linking CXX executable SomeExecutable
CMakeFiles/SomeExecutable.dir/Common/src/FunctionOne.cpp.o: In function `FunctionOne::FunctionOne(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, double, double, unsigned int, bool)':
FunctionOne.cpp:(.text+0x490): undefined reference to `Helper::initLevel(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)'
How do I fix it?
CMakeLists.txt: (shortened for brevity)
cmake_minimum_required(VERSION 3.0)
project(ProjectName)
add_definitions(-std=c++11)
add_definitions(-Wall)
add_definitions(-O2)
link_directories(/usr/local/lib)
add_executable(SomeExecutable SomeExecutable.cpp ${OptFunctionOne} ${OptFunctionTwo})
target_link_libraries(SomeExecutable -pthread -lboost_thread ${Boost_LIBRARIES} myLib armadillo)
File structure (shortened for brevity):
├── bin
├── CMakeCache.txt
├── cmake_install.cmake
├── CMakeLists.txt
├── Common
│ ├── include
│ │ ├── dataContainer.h
│ │ ├── OptFunctionOne.h
│ │ ├── OptFunctionTwo.h
│ └── src
│ ├── OptFunctionOne.cpp
│ └── OptFunctionTwo.cpp
├── SomeExecutable.cpp
├── myLib
│ ├── example.cpp
│ ├── include
│ │ ├── Config.h
│ │ ├── Helper.h
│ ├── libmyLib.so
Aucun commentaire:
Enregistrer un commentaire