简体   繁体   English

C ++库与CMake的相互依赖性

[英]Interdependancy of C++ libraries with CMake

What and how to do with CMake files in such a away one would not have to take care of the dependency order? 在如此遥远的环境下,如何处理CMake文件以及如何处理依赖顺序? (see my previous question related the issue Strange error: undefined reference to `class::class()' ). (请参阅我与问题“ 奇怪的错误:未定义对`class :: class()'的引用”相关的上一个问题)。

For instance if you have lib A dependent of lib B, which by its turn is dependent of lib C one would code 例如,如果您有一个依赖于库B的库A,而库B又依赖于库C,那么您将进行编码

add_library({MY_LIB} A B C)

How to do to not be forced to follow the order? 如何不被迫遵守命令? In the near past I just did 在不久之前,我只是做了

target_link_libraries({MY_LIB} {MY_LIB})

But this is no longer working for me.... I do not know why (???). 但是,这不再对我有用。...我不知道为什么(???)。 This problem is quite irritating since I have a large number of interdependent libraries... 因为我有大量相互依赖的库,所以这个问题很烦人。

Any suggestion please (am using cmake 3.5.2, gcc version 4.8.4 on Ubuntu 4.8.4-2ubuntu1~14.04.3)? 请提出任何建议(在Ubuntu 4.8.4-2ubuntu1〜14.04.3上使用cmake 3.5.2,gcc版本4.8.4)?

An add_library command to create each library, and then set the dependencies with target_link_libraries should be enough. 一个add_library命令创建每个库,然后设置与依赖target_link_libraries应该够了。

In your case you would have eg 就您而言,例如

add_library(A ${sources_for_A})
add_library(B ${sources_for_B})
add_library(C ${sources_for_C})

target_link_libraries(A B)  # A depends on B
target_link_libraries(B C)  # B depends on C

# Executable using the libraries
add_executable(program ${sources_for_program})
target_link_libraries(program A)  # Program uses library A (and B and C indirectly)

It should not matter if the libraries are STATIC or SHARED . 库是STATIC还是SHARED都没有关系。

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

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