简体   繁体   English

CMake 链接目标从一个子目录到另一个子目录中的目标

[英]CMake link target from one subdirectory to target in another subdiretory

I have next project structure我有下一个项目结构

/-Project
/--- LibA_folder
/--- --- CMakeLists.txt (add_library())
/--- LibB_folder
/--- --- CMakeLists.txt (add_library()) // depends on LibA
/--- Executable_folder
/--- --- CMakeLists.txt (add_executable()) // depends on LibB

When im trying to build project after this configuration sequence:当我尝试在此配置序列之后构建项目时:

add_subdirectory(libA)
add_subdirectory(libB)
add_subdirectory(executable)

It fails on libB processing, cause seems libB doesnt see sources\headers from libA .它在libB处理上失败,因为libB似乎没有看到来自libA的 sources\headers 。 As i understand, libB must know about libA through inner add_subfolder() command.据我了解, libB必须通过内部 add_subfolder() 命令了解libA

I can pass path to libA or maybe build libA inside libB , but it seem to be a "dirty" way.我可以将路径传递给libA或者在libB libA但这似乎是一种“肮脏”的方式。

What is a right way to add dependency?添加依赖项的正确方法是什么?

Seems, my problem was in what im using variables with看来,我的问题在于我将变量与

target_link_libraries(${LIB_B_NAME} ${LIB_A_NAME})

If im use name of library directly, everything is working.如果我直接使用库的名称,一切正常。

target_link_libraries(${LIB_B_NAME} "libA")

So, i must somehow pass variables from\to subdirectory, but this is off-topic.所以,我必须以某种方式将变量从\传递到子目录,但这是题外话。

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

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