简体   繁体   English

CMake链接库未显示在VisualStudio生成的项目中

[英]CMake linking library doesn't show up in VisualStudio generated project

I am generating a VisualStudio project for Windows with cmake and the provided linking functions don't appear to work on the generated VisualStudio project. 我正在使用cmake为Windows生成一个VisualStudio项目,并且提供的链接功能在生成的VisualStudio项目上似乎不起作用。

The generated project is a library and it relies on another library as a dependency. 生成的项目是一个库,它依赖于另一个库作为依赖项。

Generation of the project works fine but nothing appears under "Additional Dependencies" entry whatever i try. 该项目的生成效果很好,但是无论我如何尝试,“ Additional Dependencies”条目下都不会出现任何内容。

I tried using both "link_libraries" and "target_link_libraries", both before and after stating "add_library( MyLib )" I tried this for instance: 我在陈述“ add_library(MyLib)”之前和之后都尝试使用“ link_libraries”和“ target_link_libraries”,例如:

project( MyLib )
...
add_library( MyLib ${source_list} )
...
target_link_libraries ( MyLib ${SOME_LIB_PATH} )
target_link_libraries ( MyLib "${SOME_LIB_PATH}" )
target_link_libraries ( MyLib W:/work/Project/MyLib/ )
target_link_libraries ( MyLib "W:/work/Project/MyLib/" )
target_link_libraries ( MyLib W:/work/Project/MyLib/MyLib.lib )
target_link_libraries ( MyLib "W:/work/Project/MyLib/MyLib.lib" )
target_link_libraries ( MyLib banane )
target_link_libraries ( MyLib whatever )
target_link_libraries ( MyLib "test" )
...
include_directories(
    "Include/"
    ${SOME_LIB_INCLUDE_PATH}
)

Include directories appear correctly in the project properties though. 包含目录会正确显示在项目属性中。 So is that a bug or am i missing something :) ? 那是一个错误还是我缺少一些东西:)?

Scheff pointed me in the right direction by recalling that a static library is not actually linked against other potential static libraries. Scheff回忆起静态库实际上未与其他潜在的静态库链接的方式为我指明了正确的方向。

Even though VisualStudio allow to specify a static library dependancy in its UI, it is actually not happening and CMake shows this by actually not adding it in the generated project; 即使VisualStudio允许在其UI中指定静态库依赖关系,它实际上也没有发生,并且CMake通过实际上不将其添加到生成的项目中来显示这一点; that was the confusing part. 那是令人困惑的部分。

A static library can compile fine without being explicitely link to another static library dependancy, even if it uses code from it, as long as the final executable links with the said library AND its library dependancies, if i am not mistaken. 一个静态库可以编译良好,而不必明确地链接到另一个静态库依赖关系,即使它使用其中的代码,只要最终的可执行程序链接到所述静态库及其库依赖关系(如果我没有记错的话)也可以。

So thank you @Scheff for his comment ! 因此,谢谢@Scheff的评论!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM