且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-06-14 23:29:09

另一种方法可能是为调试库创建 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.