[英]How to tell CMake to link executable against library?
My source tree is 我的源代码树是
So Demo is the executable which is done with add_executable() and Library is obviously the library. 因此,演示是可通过add_executable()完成的可执行文件,而库显然是库。 How can those 2 be linked together?
这两个如何连接在一起?
Because right now I am using target_link_libraries(Demo Library) but I am getting Error: LNK2019 which I think is caused by not linking successfully. 因为现在我正在使用target_link_libraries(Demo库),但出现错误:LNK2019,我认为是由于未成功链接所致。
Any ideas? 有任何想法吗?
Thanks. 谢谢。
edit: On root CMakeLists.txt those 2 are added as -> add_subdirectory(Library) add_subdirectory(Demo). 编辑:在根CMakeLists.txt上,将这2个添加为-> add_subdirectory(Library)add_subdirectory(Demo)。
edit2: EDIT2:
Demo CMakeLists 演示CMakeLists
add_executable(Demo ${Headers}
${Source})
target_link_libraries(Demo ${blahblah}
${Library})
Library CMakeLists 图书馆CMakeLists
add_library(Library blahblah.cpp
blahblah.h
foo.cpp
foo.h)
This is incorrect: 这是不正确的:
target_link_libraries(Demo ${blahblah}
${Library})
What you are saying is to use the string variable called Library, which won't exist. 您要说的是使用名为Library的字符串变量,该变量将不存在。
Use: 采用:
target_link_libraries(Demo ${blahblah}
Library)
so that CMake will know you are referencing the target "Library" and not a variable. 这样CMake就会知道您正在引用目标“库”而不是变量。
In your example above, Library is a target name, not a variable. 在上面的示例中,“库”是目标名称,而不是变量。 When you link it to your executable, use
target_link_libraries(Demo Library)
(no '${}' around 'Library'). 将其链接到可执行文件时,请使用
target_link_libraries(Demo Library)
(“库”周围没有“ $ {}”)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.