链接到名为"debug"的库在cmake中

编程入门 行业动态 更新时间:2024-10-27 07:20:37
本文介绍了链接到名为"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中

本文发布于:2023-11-13 11:56:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584293.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:链接   quot   cmake   debug

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!