CMake cannot determine linker language for target(CMake 无法确定目标的链接器语言)
问题描述
首先,我查看了this 发布后找不到我的问题的解决方案.我正在尝试使用两个头文件在文件夹中设置一个库并与我的主程序链接,在我的文件夹 container 中,它包括:
To start off, I've taken a look at this post and couldn't find a solution to my problem. I'm attempting to set up a library in a folder using two header files and link with my main program, in my folder container it includes:
linkedStack.h
linkedQueue.h
我的容器文件夹中的 CMakeLists.txt 是
the CMakeLists.txt in my container folder is
add_library(container linkedQueue.h linkedStack.h)
install (TARGETS container DESTINATION bin)
install (FILES linkedQueue.h linkedStack.h DESTINATION include)
而我在源目录中的 CMakeLists.txt 是:
while my CMakeLists.txt in the source directory is:
cmake_minimum_required(VERSION 2.6)
project(wordLadder)
# set version number
set (MAJOR 1)
set (MINOR 0)
# configure header file to be placed in binary
configure_file(
"${PROJECT_SOURCE_DIR}/ladderConfig.h.in"
"${PROJECT_BINARY_DIR}/ladderConfig.h"
)
# add binary tree to search path for include files
# so we can find config
include_directories("${PROJECT_BINARY_DIR}")
#add container library
include_directories ("${PROJECT_SOURCE_DIR}/container")
add_subdirectory(container)
#add executable
add_executable(wordLadder ladderMain.cpp)
target_link_libraries (wordLadder container)
install (TARGETS wordLadder DESTINATION bin)
install (FILES "${PROJECT_BINARY_DIR}/ladderConfig.h"
DESTINATION include)
以及我得到的错误:
CMake Error: Cannot determine link language for target "container".
CMake Error: CMake can not determine linker language for target:container
-- Generating done
-- Build files have been written to: /home/gmercer/Linux_dev/wordLadder/build
我不确定我在这里做错了什么,但我认为这与我的库 CMake 文件有关.
I'm not sure what i'm doing wrong here, but I think it has something to do with my library CMake file.
推荐答案
您已添加用于创建 container
库的目标.该目标仅包含头文件.请参阅 CMake 文档
You have added target for creating container
library. That target contains only header files. See CMake documentation
add_library:使用指定的源文件向项目添加库.
add_library: Add a library to the project using the specified source files.
add_library( [静态 | 共享 | 模块][EXCLUDE_FROM_ALL]source1 source2 ... sourceN)
add_library( [STATIC | SHARED | MODULE] [EXCLUDE_FROM_ALL] source1 source2 ... sourceN)
添加一个库目标,称为从命令调用中列出的源文件构建.对应于逻辑目标名称,并且必须在项目中全局唯一.构建的库的实际文件名是根据本机平台的约定(例如lib.a 或.lib)构建的.
Adds a library target called to be built from the source files listed in the command invocation. The corresponds to the logical target name and must be globally unique within a project. The actual file name of the library built is constructed based on conventions of the native platform (such as lib.a or .lib).
但是你不能只从没有任何 cpp 文件的头文件构建库.这就是为什么你会出现这样的错误.
But you can not build library just from header files without any cpp file. That's why you got such error.
这篇关于CMake 无法确定目标的链接器语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CMake 无法确定目标的链接器语言
- Stroustrup 的 Simple_window.h 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 近似搜索的工作原理 2021-01-01
- C++ 协变模板 2021-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 从python回调到c++的选项 2022-11-16
- 静态初始化顺序失败 2022-01-01