链接到名为"debug"的库在cmake中 [英] Linking against a library called "debug" in cmake

查看:634
本文介绍了链接到名为"debug"的库在cmake中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在切换使用cmake,而我正在构建的应用程序之一使用了一个名为"debug"的库. (假设它位于/path/to/libdebug.so).

We are switching to use cmake, and one of the applications I'm building use a library called "debug". (Say it's located at /path/to/libdebug.so).

我意识到跟随调试不起作用是一个特殊的关键字.

I realized that following doesn't work as debug is a special keyword.

add_executable(myapp myapp.cpp)
target_link_libraries(myapp lib1 lib2 debug lib3)

这都不行,

add_executable(myapp myapp.cpp)
target_link_libraries(myapp lib1 lib2 lib3 debug)

因为它抱怨

"debug"参数后面必须有一个库

The "debug" argument must be followed by a library

在cmake中是否有任何解决方法?为了能够继续工作,我将libdebug.so复制到libdebug2.so,并针对debug2进行链接.但是我需要在cmake中找到一个长期解决方案,因为libdebug.so也被其他项目使用,我不能简单地更改其名称.

Is there any workaround for this in cmake? For now to be able to continue working, I copied libdebug.so to libdebug2.so and I'm linking against debug2. But I need to find a long-term solution in cmake as libdebug.so is used by other projects too and I can't simply change it's name.

推荐答案

另一种方法可能是为调试库创建 IMPORTED 目标:

Another approach could be creating IMPORTED target for debug library:

find_library(DEBUG_LIBRARY debug PATH <directory-contained-the-library> NO_DEFAULT_PATH)
add_library(debug_lib SHARED IMPORTED)
set_target_properties(debug_lib PROPERTIES IMPORTED_LOCATION ${DEBUG_LIBRARY})

此目标然后可用于与以下对象链接:

This target then may be used for link with:

target_link_libraries(myapp lib1 lib2 lib3 debug_lib)

尽管这种方法比使用完整的库名需要更多的行(和变量),但它是平台无关的:CMake自动选择搜索的库扩展名.

While this approach requires more lines (and variables) than using full library name, it is platform independent: extension of the library searched is choosen automatically by CMake.

这篇关于链接到名为"debug"的库在cmake中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆