开发者

CMake : link a produced library?

开发者 https://www.devze.com 2023-03-29 02:57 出处:网络
I have a huge project with 2 main directories : - /myproject/src - /myproject/app The strategy is that src produces libraries in the /myproject/lib directory and then apps use these libraries to pro

I have a huge project with 2 main directories : - /myproject/src - /myproject/app

The strategy is that src produces libraries in the /myproject/lib directory and then apps use these libraries to produce executables in /myproject/bin directory.

But the problem is the following. The开发者_开发问答 classic stategy to link libraries is to use the FIND_LIBRARY(). But how to link a library that is not already produced ?

Thank you.


find_library() is a little more than the name suggests, it not only finds the path to a (preinstalled) lib, but often also prepares a lot of variables and functions. Also find_library() only works with specific library modules, which reside in the cmake/share directory.

When you build your own library you have to add it to the CMakeLists.txt with the add_library() command, which works exactly like the add_executable() command.

When you have done that, you can actually add the library to the executable using the target_link_libraries() command.

To sum it up:

add_library(myLib libsourceA.c libSourceB.c)

add_executable(myProgram prgsourceA.c prgsourceB.c)
target_link_libraries(myProgram myLib)

You actually don't have to know or specify the exact location of the library-file, cmake will manage that for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消