问题
I created the following Directory:
FrameWork/
├── CMakeLists.txt ==> contains only add_subdirectory(UtilsBasic)
└── UtilsBasic
├── CMakeLists.txt ==> Contains only add_subdirectory(SmartSingleton)
└── SmartSingleton
├── CMakeLists.txt
├── include
│ └── SmartSingleton.hpp
The CMakeLists.txt
in SmartSingleton
directory contains:
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/)
The main CMakeLists.txt
of the project is the following:
cmake_minimum_required (VERSION 3.4)
project (MyProject)
USR_init_project(MyProject)
add_subdirectory(src/FrameWork)
Error
-- Configuring done CMake Error: CMake can not determine linker language for target: SmartSingleton CMake Error: Cannot determine link language for target "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
.
回答1:
Try this in your SmartSingleton/CMakeLists.txt
file:
set_target_properties(SmartSingleton PROPERTIES LINKER_LANGUAGE CXX)
This will directly tell CMake which language to use for that target.
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/)
Here are the docs for INTERFACE
libraries.
来源:https://stackoverflow.com/questions/56462415/cmake-error-cannot-determine-link-language-for-target