【发布时间】:2020-04-16 09:48:55
【问题描述】:
我在 CMake 中有这段代码,用于为我拥有的项目查找调试和发布库:
FIND_LIBRARY(MP4V2_LIBRARY_RELEASE libmp4v2 HINTS "${MP4V2_DIR}/bin/Windows-x64/Release Static (MT)")
FIND_LIBRARY(MP4V2_LIBRARY_BEDUG libmp4v2 HINTS "${MP4V2_DIR}/bin/Windows-x64/Debug Static (MTd)")
set(MP4V2_LIBRARIES "optimized ${MP4V2_LIBRARY_RELEASE} debug ${MP4V2_LIBRARY_BEDUG}")
message(STATUS ${MP4V2_LIBRARIES})
当我运行 CMake 时它会正确展开:
optimized D:/MyData/SourceCode/camm_mp4v2/bin/Windows-x64/Release Static (MT)/libmp4v2.lib debug D:/MyData/SourceCode/camm_mp4v2/bin/Windows-x64/Debug Static (MTd)/libmp4v2.lib
然后我像这样将它添加到我的应用程序中:
target_link_libraries(MyApp ${MP4V2_LIBRARIES})
当我为 VS 创建项目并尝试编译它时,我收到此错误:
cannot open file 'optimized D:\MyData\SourceCode\camm_mp4v2\bin\Windows-x64\Release Static (MT)\libmp4v2.lib debug D:\MyData\SourceCode\camm_mp4v2\bin\Windows-x64\Debug Static (MTd)\libmp4v2.lib.lib'
显然,CMake 没有检测到优化和调试库。
这段代码有什么问题,我该如何解决?
【问题讨论】:
-
您想将
optimized、${MP4V2_LIBRARY_RELEASE}、debug和debug的列表 分配给变量MP4V2_LIBRARIES,但将此列表包含在 中双引号...因此,变量的值不是列表,而是由4个空格分隔的单词组成的字符串。您在message()输出中观察到的正是这一点。删除双引号或用分号分隔单词;。 -
@Tsyvarev 这解决了我的问题。请提出作为答案,我会接受。
标签: c++ visual-studio cmake