CMake无法确定目标的链接器语言 [英] CMake cannot determine linker language for target

查看:607
本文介绍了CMake无法确定目标的链接器语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我查看了发布,找不到我的问题的解决方案。我试图在使用两个头文件的文件夹中建立一个库,并与我的主程序链接,在我的文件夹容器中,它包括:

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.

推荐答案

您已添加了创建容器库的目标。该目标仅包含头文件。请参见 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([STATIC | SHARED | MODULE]
[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无法确定目标的链接器语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆