使用调试后缀(_d)引导cmake链接共享对象 [英] Directing cmake to link against shared object with debug postfix (_d)

查看:91
本文介绍了使用调试后缀(_d)引导cmake链接共享对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个cmake项目,看起来像这样:

I've got a cmake project that pretty much looks like this:

cmake_minimum_required(VERSION 3.0)

SET(CMAKE_DEBUG_POSTFIX "_d")

include_directories(../TransfunctionerProject)
include_directories(../TransmogrifierProject)

set(Libraries
    ContinuumTransfunctioner
    Transmogrifier
)

set(SourceFiles
    Wrapper.cpp
    Logger.cpp
)

add_library(Frobnigator SHARED ${SourceFiles})
add_library(FrobnigatorStatic STATIC ${SourceFiles})
set_target_properties(FrobnigatorStatic PROPERTIES OUTPUT_NAME Frobnigator)
target_link_libraries(Frobnigator ${Libraries})

其中ContinuumTransfunctioner和Transmogrifier项目包括调试后缀指令 SET(CMAKE_DEBUG_POSTFIX _d),这样 libContinuumTransfunctioner_d.so libTransmogrifier_d.so 都存在。

Where ContinuumTransfunctioner and Transmogrifier projects include the debug postfix directive SET(CMAKE_DEBUG_POSTFIX "_d") so that libContinuumTransfunctioner_d.so and libTransmogrifier_d.so both exist.

问题是当前项目似乎正在链接到没有后缀的 static 库,并抱怨:

The problem is that the current project appears to be linking against the static library without the _d suffix and complains:

/usr/bin/ld: cannot find -lContinuumTransfunctioner


推荐答案

这是解决方法,由 cmake邮件列表

# Note:
#    $<$<CONFIG:Debug>:_d> is called a generator expression.
#    It outputs _d if the build is debug.
#
set(Libraries
    ContinuumTransfunctioner$<$<CONFIG:Debug>:_d>
    Transmogrifier$<$<CONFIG:Debug>:_d>
)

这篇关于使用调试后缀(_d)引导cmake链接共享对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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