CMake: Attempting to add a targeting link library that is not built in this directory

I had a problem compiling some unit tests in my cmake project. The idea is to add these control unit tests as executable files so that I can run them. Anyway, I get this error, which I do not understand, and this suggests that I can not link the cpp module tests, which should be related to checking the library that I created. The two unit tests I'm trying to link and add as executables are DownloadTickers.cpp and GetTickersForLetter.cpp.

My directory structure is as follows:

> Algo > build (this is where I do: cmake .. which gives me errors) -CMakeLists.txt (top level cmake) -algo.h.ini -run.cpp > NetworkModule > CrawlTickers -CMakeLists.txt -CrawlTickers.cpp -CrawlTickers.hpp > tests -CMakeLists.txt -DownloadTickers.cpp -GetTickersForLetter.cpp 

CMakeLists.txt for Algo:

 cmake_minimum_required (VERSION 2.8) project (Algo) set (Algo_VERSION_MAJOR 0) set (Algo_VERSION_MINOR 1) set (CMAKE_CXX_COMPILER g++-4.8) set (CMAKE_BUILD_TYPE Release) add_definitions( -std=c++11 ) configure_file( "${PROJECT_SOURCE_DIR}/algo.h.in" "${PROJECT_BINARY_DIR}/algo.h" ) include_directories("${PROJECT_BINARY_DIR}") add_subdirectory(NetworkModule/CrawlTickers) add_executable(Run run.cpp) 

CMakeLists.txt for CrawlTickers:

 find_package(Boost COMPONENTS system filesystem unit_test_framework REQUIRED) add_library(CrawlTickers SHARED CrawlTickers.cpp) add_subdirectory(tests) target_link_libraries( CrawlTickers cpprest ) target_link_libraries( DownloadTickers CrawlTickers ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} ) target_link_libraries( GetTickersForLetter CrawlTickers ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} ) 

CMakeLists.txt for tests:

 add_executable( DownloadTickers DownloadTickers.cpp ) add_executable( GetTickersForLetter GetTickersForLetter.cpp ) 

My thinking is that cmake naturally registers DownloadTickers and GetTickersForLetter as executable files in CrawlTickers CMakeLists.txt, and then knows how to link it to the target, but I have no idea why I get this error. Any help is appreciated. Thanks.

+6
source share
1 answer

The target_link_libraries directive should be part of the same CMakeLists.txt as the add_executable directive. This also applies to libraries. Think of each directory and related CMakeLists.txt as a subproject.

+3
source

Source: https://habr.com/ru/post/977964/


All Articles