使用CMake链接静态库 [英] Link static library using CMake

查看:1190
本文介绍了使用CMake链接静态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用CMake使库${static_library}静态链接.我已经尝试过对路径进行硬编码,据我所知TARGET_LINK_LIBRARIES应该自动将其链接.

I cannot get the library ${static_library} to statically link using CMake. I have tried hard coding the path and as far as I'm aware TARGET_LINK_LIBRARIES should link this in automatically.

ADD_LIBRARY(libraryA STATIC ${source_files})
TARGET_LINK_LIBRARIES(libraryA debug ${static_library})

有一个子项目可以在以后的版本中链接libraryA

There is a sub project that links libraryA later in the build

ADD_EXECUTABLE(testA ${test_sources}) 
TARGET_LINK_LIBRARIES(testA libraryA)

已正确链接了$ {static_library},但我需要${static_library}才能直接链接到libraryA.

which has ${static_library} correctly linked in but I need ${static_library} to be directly linked into libraryA.

推荐答案

您不能将库直接链接到库中.

You cannot link libraries into libraries directly.

某些编译器允许您执行此操作(例如,MS Visual Studio有一个选项),而其他编译器则不允许这样做,这就是CMake也不允许这样做的原因.参见此回答您将如何处理此问题.

Some compilers allow you to do this (e.g. MS Visual Studio has an option), but others don't, which is why CMake also won't allow it. See this answer for what your options are to deal with this.

这篇关于使用CMake链接静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆