CMake错误:无法确定目标的链接语言 [英] CMake Error: Cannot determine link language for target
问题描述
我创建了以下目录:
FrameWork/
├── CMakeLists.txt ==> contains only add_subdirectory(UtilsBasic)
└── UtilsBasic
├── CMakeLists.txt ==> Contains only add_subdirectory(SmartSingleton)
└── SmartSingleton
├── CMakeLists.txt
├── include
│ └── SmartSingleton.hpp
SmartSingleton 目录中的 CMakeLists.txt
包含:
set(codeprod_list
include/SmartSingleton.hpp)
USR_add_shared_lib(SmartSingleton "${codeprod_list}")
target_link_libraries(SmartSingleton PUBLIC Common)
target_include_directories(SmartSingleton PUBLIC include/)
该项目的主要 CMakeLists.txt
如下:
cmake_minimum_required (VERSION 3.4)
project (MyProject)
USR_init_project(MyProject)
add_subdirectory(src/FrameWork)
错误
-配置完成的CMake错误:CMake无法确定目标:SmartSingleton的链接器语言CMake错误:无法确定链接目标"SmartSingleton"的语言.
-- Configuring done CMake Error: CMake can not determine linker language for target: SmartSingleton CMake Error: Cannot determine link language for target "SmartSingleton".
我不明白为什么会出现该错误.我的意思是,在 Framework
中,我创建了 UtilsBasic
的链接,然后又创建了 SmartSingleton
的链接.
I don't understand Why I am getting that Error. I mean In the Framework
I created a link to UtilsBasic
and in turn a link to SmartSingleton
.
推荐答案
在您的 SmartSingleton/CMakeLists.txt
文件中尝试以下操作:
Try this in your SmartSingleton/CMakeLists.txt
file:
set_target_properties(SmartSingleton属性LINKER_LANGUAGE CXX)
这将直接告诉CMake用于该目标的语言.
This will directly tell CMake which language to use for that target.
如果您的库实际上只是头文件,则可能还会收到您提到的错误.考虑将此库设为 INTERFACE
库:
If your library is truly only header files though, you will likely receive the error you mention also. Consider making this library an INTERFACE
library:
add_library(SmartSingleton INTERFACE)
target_include_directories(SmartSingleton INTERFACE include/)
以下是 docs 用于接口
库.
这篇关于CMake错误:无法确定目标的链接语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!