Ahsan Roy
Ahsan Roy

Reputation: 201

CMake Error: CMake can not determine linker language for target: myapp

I am trying to compile vMime by cmake, but I am getting error above, I am using graphical interface of cmake and my makefiles.txt is below. It configures properly but do not generate

cmake_minimum_required(VERSION 2.8)
PROJECT(CXX)#vmime
enable_language(CXX)
set(VerifyCXX VerifyCXX.cxx)
add_definitions(-DVERIFY_CXX)
set_target_properties(${TARGET} PROPERTIES LINKER_LANGUAGE Cxx)
add_executable(myapp vmime)
install(TARGETS myapp DESTINATION bin)

Help will be highly appreciated as I am stuck at point for couple of days.

Upvotes: 8

Views: 36250

Answers (3)

Jayhello
Jayhello

Reputation: 6602

I use clion IDE based on cmake, my source files named *.cc

project(server)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread")
file(GLOB SRC_FILE "main.cc" "listenfd.cc" "socket_util.cc"
    "timers.cc" "network.cc" "main_event.cc")
add_executable(server ${server})
set_target_properties(server PROPERTIES LINKER_LANGUAGE CXX)

after I change

add_executable(server ${server}) to 
add_executable(server "main.cc")

then I solved it, I really don't know why? after experiment I found when use file(GLOB ....) like file(GLOB "src/main.cc") I must specify the relative path, then it works.

Upvotes: 0

sage
sage

Reputation: 5514

For others' benefit, make sure you did not overlook an earlier error such as:

Cannot find source file:

    MyFirstSourceFile.cpp

Another way to cause CMake to give you the error, "CMake Error: CMake can not determine linker language for target: myapp", is if you mistakenly point it exclusively at sources that do not exist.

For instance: I'm moving files from one directory to another and had the pre-move files with the post-move paths in my CMakeLists.txt. My output window is not very tall and I focused too soon on the "can not determine linker language" error!

Upvotes: 3

Peter Petrik
Peter Petrik

Reputation: 10195

CMake probably can not determine linker language for target myapp, because the target does not contain any source files with recognized extensions.

add_executable(myapp vmime)

should be probably replaced by

add_executable(myapp ${VerifyCXX})

Also this command

set_target_properties(${TARGET} PROPERTIES LINKER_LANGUAGE Cxx) 

cannot be succesfull, because ${TARGET} is used-before-set. You should call it after add_executable

set_target_properties(myapp PROPERTIES LINKER_LANGUAGE CXX)

Note that usually it is not needed at all.

Upvotes: 11

Related Questions