External library Cmake.a

I have an external library here:

${PROJECT_SOURCE_DIR}/thirdparty/yaml-cpp/

Runs Makefile: thirdparty/Makefile . I execute this make file as follows:

 add_custom_target( yaml-cpp COMMAND make WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/thirdparty ) 

Then I try to link the library which is building on thirdparty/yaml-cpp/build/libyaml-cpp.a . This is the part that does not work :

 target_link_libraries(load_balancer_node ${CMAKE_SOURCE_DIR}/thirdparty/yaml-cpp/build/libyaml-cpp.a) 

I get an error message:

  Target "yaml-cpp" of type UTILITY may not be linked into another target. One may link only to STATIC or SHARED libraries, or to executables with the ENABLE_EXPORTS property set. 

How to execute this make file and link the .a file?

+4
source share
1 answer

So, it makes sense that cmake cannot determine the dependencies here: it will have to parse the makefile and find the output. You have to say that this is the result. The closest I can understand, the best way to do this is to use custom_command, rather than a custom target:

 add_custom_command( OUTPUT ${CMAKE_SOURCE_DIR}/thirdparty/yaml-cpp/build/libyaml-cpp.a COMMAND make WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/thirdparty) add_custom_target( yaml-cpp DEPENDS ${CMAKE_SOURCE_DIR}/thirdparty/yaml-cpp/build/libyaml-cpp.a) ... add_dependencies(load_balancer_node yaml-cpp) target_link_libraries(load_balancer_node ${CMAKE_SOURCE_DIR}/thirdparty/yaml-cpp/build/libyaml-cpp.a) 

I had problems with linkers, though (dumb window computer), but cmake worked and made libraries before trying to link.

+4
source

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


All Articles