On 19.06.19 15:36, dexter810 wrote: > *Approach 1:* > CMakeLists.txt: > > cmake_minimum_required(VERSION 3.6) > project(main CXX C) > > add_executable(main main.cpp) > > target_include_directories(main PRIVATE > include build/deps/yara/src/yara/libyara/include) > > > target_link_libraries (main > -Lbuild/src/ -Lbuild/deps/yara/src/yara/libyara/.libs > yaracpp yara pthread ssl crypto)
I've done a little testing - the reason this approach doesn't work is because when CMake calls the linker, the current directory is not the source directory, but the build directory. For this approach to work you would need to write: target_include_directories(main PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/build/deps/yara/src/yara/libyara/include) target_link_libraries (main -L${CMAKE_CURRENT_SOURCE_DIR}/build/src/ -L${CMAKE_CURRENT_SOURCE_DIR}/build/deps/yara/src/yara/libyara/.libs yaracpp yara pthread ssl crypto) > * > Approach 2:* > > CMakeLists.txt: > cmake_minimum_required(VERSION 3.6) > project(main CXX C) > > add_executable(main main.cpp) > > > > add_library(yara STATIC IMPORTED) > set_target_properties(yara PROPERTIES > IMPORTED_LOCATION > "build/deps/yara/src/yara/libyara/.libs/libyara.a" > INTERFACE_INCLUDE_DIRECTORIES > "build/deps/yara/src/yara/libyara/include") > > add_library(yaracpp STATIC IMPORTED) > set_target_properties(yaracpp PROPERTIES > IMPORTED_LOCATION "build/src/libyaracpp.a" > INTERFACE_INCLUDE_DIRECTORIES "include") This cannot work because you forgot the target_link_libraries(main yara yaracpp pthread ssl crypto) CMake is not psychic, you need to explicitly tell it which libraries main will be needing. > Approach 3* > CMakeLists.txt: > cmake_minimum_required(VERSION 3.6) > project(main CXX C) > > add_executable(main main.cpp) > > target_include_directories(main PRIVATE > include build/deps/yara/src/yara/libyara/include) > > > target_link_libraries (main > -Lbuild/src/libyaracpp.a > -Lbuild/deps/yara/src/yara/libyara/.libs/libyara.a > yaracpp yara pthread ssl crypto) This approach cannot work because the -L option tells the compiler in which (additional) directory to look for libraries. If you want to use the full path to the library, you would use: target_link_libraries (main build/src/libyaracpp.a build/deps/yara/src/yara/libyara/.libs/libyara.a yaracpp yara pthread ssl crypto) > Also, inside target_link_libraries() irrespective of putting -lyaracpp and > -lyara or yaracpp and yara, I got the same errors. I believe CMake will automatically add the -l if you specify an argument to target_link_libraries that is not a CMake target itself and not an absolute path when building for Unix-like systems. -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake