Cmake external library .a
Cmake external library .a
我在这里有一个外部库:
${PROJECT_SOURCE_DIR}/thirdparty/yaml-cpp/
它是由一个Makefile创建的:thirdparty/Makefile
。我正在执行这样的makefile:
add_custom_target(
yaml-cpp
COMMAND make
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/thirdparty
)
然后我尝试将库链接到thirdparty/yaml-cpp/build/libyaml-cpp.a
这是不工作的部分:
target_link_libraries(load_balancer_node ${CMAKE_SOURCE_DIR}/thirdparty/yaml-cpp/build/libyaml-cpp.a)
我得到错误:
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.
如何执行makefile并链接.a
文件
所以cmake不能在这里找出依赖项是有道理的:它必须解析makefile并找到输出。你必须告诉它输出的人。我能想到的最好的方法是使用custom_command而不是自定义目标:
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)
虽然我遇到了链接器的问题(愚蠢的windows机器),但cmake在尝试链接之前已经工作并制作了库。
相关文章:
- Boost Graph Library,修复节点大小
- SFML library: http request
- CppSQLite 抛出"LNK2019: unresolved external symbol"错误
- 解决"ld: library not found for -ltensorflow_framework.2.3.0"
- Linking library C++
- 在VS2019项目中集成ImageMagick:x64-windows-static library
- OpenSSL fips in C++ wrapper Library 如何?错误:指纹不匹配
- Visual Studio中的wxwidgets应用程序给出错误"LNK2019 unresolved external symbol"
- C++ class vs a library
- C++ library with Tensorflow on Android
- 在 C++ 中嵌入 V8 会导致与 libcpp 相关的"unrecognized external symbol"错误
- CMake:尝试在 Jenkins 构建机器上运行时出现"Linked Library"错误 (0xc0000135)
- 将 c++ cmake-library 构建发布到本地存储库时出现 Gradle 错误
- 我的游戏引擎的 spdlog 日志记录出现奇怪的"unresolved external symbol"错误
- 为什么'allocate in one library and free in the other'是错误的
- 如何修复"unresolved external symbol _gladLoadGLLoader referenced in function _main"和"unresolved external
- Android Studio External Native Build 预编译标头
- 在 R 中调用"multi file C++ code with external libraries referenced"
- 对"function name from external library"的未定义引用
- Cmake external library .a