【发布时间】:2020-11-09 19:49:34
【问题描述】:
我第一次在 VS2019 中尝试 CMake,但对它的工作原理感到困惑。 这是在 Windows 10 中使用 msvc_x64_x64 工具集。
我有一个创建静态库的 CMake 项目,我想使用动态链接。 默认的 CMakeSettings.json 包含变量
CMAKE_CXX_FLAGS_DEBUG = /MDd /Zi /Ob0 /Od /RTC1
CMakeLists.txt 不会覆盖它,所以它对我来说很好。
但是,生成的 lib 文件似乎使用静态链接,另一个项目可以使用运行时库 /MTd 而不是 /MDd 链接到它。
所以它似乎是从其他地方获取编译器标志并忽略 CMakeSettings.json 中的那些,或者除了 CMAKE_CXX_FLAGS_DEBUG 之外还有一些变量。
如何让它使用 CMakeSettings.json 变量?
这是当前的 CMakeSettings.json 文件
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Visual Studio 16 2019 Win64",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"variables": [
{
"name": "CMAKE_CXX_FLAGS_DEBUG",
"value": "/MDd /Zi /Ob0 /Od /RTC1",
"type": "STRING"
}
]
},
{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64_x64" ],
"variables": []
}
]
}
【问题讨论】:
-
你用的是什么生成器?
-
我试过 Ninja 和微软的
-
您介意发布您的整个 CmakeSettings.json 吗?应该不会那么多。
-
感谢您的关注。 @hdf89shfdfs 文件在上面添加。
标签: visual-c++ cmake visual-studio-2019 microsoft-runtime-library