Syntactic Fructose
Syntactic Fructose

Reputation: 20076

CMake cannot determine linker language for target

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

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)

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)

and the error I get:

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

I'm not sure what i'm doing wrong here, but I think it has something to do with my library CMake file.

Upvotes: 16

Views: 49665

Answers (2)

MoralCode
MoralCode

Reputation: 2050

As this is the canonical answer for "CMake cannot determine linker language for target", I found that when trying to link C code to c++ code and having everything else seemingly be right, this random forum post was the answer:

Try changing

PROJECT(HelloWorld C)

into

PROJECT(HelloWorld C CXX)

or just

PROJECT(HelloWorld)

(Source : https://exceptionshub.com/cmake-unable-to-determine-linker-language-with-c.html)

I noticed you are already doing this in your code, but I wanted to leave this here in case others have this same error for a different reason

Upvotes: 3

Nikolay Viskov
Nikolay Viskov

Reputation: 1016

You have added target for creating container library. That target contains only header files. See CMake documentation

add_library: Add a library to the project using the specified source files.

add_library( [STATIC | SHARED | MODULE] [EXCLUDE_FROM_ALL] source1 source2 ... sourceN)

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).

But you can not build library just from header files without any cpp file. That's why you got such error.

Upvotes: 16

Related Questions