Cmake error cannot determine link 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 f...

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.

I’m attempting to run a cmake hello world program on Windows 7 x64 with both Visual Studio 2010 and Cygwin, but can’t seem to get either to work. My directory structure is as follows:

HelloWorld
-- CMakeLists.txt
-- src/
-- -- CMakeLists.txt
-- -- main.cpp
-- build/

I do a cd build followed by a cmake .., and get an error stating that

CMake Error: CMake can not determine linker language for target:helloworld
CMake Error: Cannot determine link language for target "helloworld".

However, if I change the extension of main.cpp to main.c both on my filsystem and in src/CMakeLists.txt everything works as expected. This is the case running from both the Visual Studio Command Prompt (Visual Studio Solution Generator) and the Cygwin Terminal (Unix Makefiles Generator).

Any idea why this code wouldn’t work?

CMakeLists.txt

PROJECT(HelloWorld C)
cmake_minimum_required(VERSION 2.8)

# include the cmake modules directory
set(CMAKE_MODULE_PATH ${HelloWorld_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})

add_subdirectory(src)

src/CMakeLists.txt

# Include the directory itself as a path to include directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)

# Create a variable called helloworld_SOURCES containing all .cpp files:
set(HelloWorld_SOURCES main.cpp)

# Create an executable file called helloworld from sources:
add_executable(hello ${HelloWorld_SOURCES })

src/main.cpp

int main()
{
  return 0;
}

asked Aug 3, 2012 at 18:19

Chris Covert's user avatar

Chris CovertChris Covert

2,6543 gold badges23 silver badges31 bronze badges

3

I also got the error you mention:

CMake Error: CMake can not determine linker language for target:helloworld
CMake Error: Cannot determine link language for target "helloworld".

In my case this was due to having C++ files with the .cc extension.

If CMake is unable to determine the language of the code correctly you can use the following:

set_target_properties(hello PROPERTIES LINKER_LANGUAGE CXX)

The accepted answer that suggests appending the language to the project() statement simply adds more strict checking for what language is used (according to the documentation), but it wasn’t helpful to me:

Optionally you can specify which languages your project supports.
Example languages are CXX (i.e. C++), C, Fortran, etc. By default C
and CXX are enabled. E.g. if you do not have a C++ compiler, you can
disable the check for it by explicitly listing the languages you want
to support, e.g. C. By using the special language «NONE» all checks
for any language can be disabled. If a variable exists called
CMAKE_PROJECT__INCLUDE_FILE, the file pointed to by that
variable will be included as the last step of the project command.

tambre's user avatar

tambre

4,4844 gold badges45 silver badges55 bronze badges

answered May 21, 2013 at 11:40

Joakim's user avatar

JoakimJoakim

11.1k9 gold badges44 silver badges50 bronze badges

2

In my case, it was just because there were no source file in the target. All of my code was a template with the source code in the header file. Adding an empty file.cpp solved the problem.

answered Apr 8, 2015 at 14:52

Moebius's user avatar

MoebiusMoebius

6,0377 gold badges40 silver badges53 bronze badges

6

Confusing as it might be, the error also happens when a cpp file included in the project does not exist.

If you list your source files in CMakeLists.txt and mistakenly type a file name then you get this error.

answered Apr 4, 2018 at 6:14

Jolly Roger's user avatar

Jolly RogerJolly Roger

2232 silver badges6 bronze badges

1

I want to add another solution in case a library without any source files shall be build. Such libraries are also known as header only libraries. By default add_library expects at least one source file added or otherwise the mentioned error occurs. Since header only libraries are quite common, cmake has the INTERFACE keyword to build such libraries. The INTERFACE keyword is used as shown below and it eliminates the need for empty source files added to the library.

add_library(myLibrary INTERFACE)
target_include_directories(myLibrary INTERFACE {CMAKE_CURRENT_SOURCE_DIR})

The example above would build a header only library including all header files in the same directory as the CMakeLists.txt. Replace {CMAKE_CURRENT_SOURCE_DIR} with a path in case your header files are in a different directory than the CMakeLists.txt file.

Have a look at this blog post or the cmake documentation for further info regarding header only libraries and cmake.

answered Oct 18, 2020 at 16:48

zhm's user avatar

zhmzhm

1712 silver badges7 bronze badges

1

A bit unrelated answer to OP but for people like me with a somewhat similar problem.

Use Case: Ubuntu (C, Clion, Auto-completion):

I had the same error,

CMake Error: Cannot determine link language for target «hello».

set_target_properties(hello PROPERTIES LINKER_LANGUAGE C) help fixes that problem but the headers aren’t included to the project and the autocompletion wont work.

This is what i had

cmake_minimum_required(VERSION 3.5)

project(hello)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES ./)

add_executable(hello ${SOURCE_FILES})

set_target_properties(hello PROPERTIES LINKER_LANGUAGE C)

No errors but not what i needed, i realized including a single file as source will get me autocompletion as well as it will set the linker to C.

cmake_minimum_required(VERSION 3.5)

project(hello)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES ./1_helloworld.c)

add_executable(hello ${SOURCE_FILES})

answered Aug 1, 2019 at 14:59

f_i's user avatar

f_if_i

2,90428 silver badges30 bronze badges

1

I also faced a similar error while compiling my C-based code. I fixed the issue by correcting the source file path in my cmake file. Please check the source file path of each source file mentioned in your cmake file. This might help you too.

Robert Columbia's user avatar

answered Jun 20, 2018 at 9:46

user2999709's user avatar

0

Simply check the path to source file. (to the respective cpp)

answered Oct 14, 2021 at 4:26

Rahul Das's user avatar

Rahul DasRahul Das

1151 silver badge5 bronze badges

By default the JNI Native folder is named as jni . Renaming it to cpp fixed the issue

answered Apr 25, 2018 at 10:29

HimalayanCoder's user avatar

HimalayanCoderHimalayanCoder

9,4426 gold badges58 silver badges59 bronze badges

I managed to solve mine, by changing

add_executable(file1.cpp)

to

add_executable(ProjectName file1.cpp)

Zoe stands with Ukraine's user avatar

answered Oct 25, 2018 at 12:22

AKJ's user avatar

AKJAKJ

8522 gold badges13 silver badges18 bronze badges

The CMake Error: “Cannot determine link language for target” is an important warning. This error occurs when C++ files with a.cc extension are not being linked with the right compiler. In this case, the compiler should stop, and the build will fail. To resolve this issue, the first step is to learn how to fix CMake Error. To find out more, read the following sections.

This error message appears when the linker cannot determine the target link language. The target file is in another language. You should use that file if the error occurs. You can also manually edit the build files by double-clicking the corresponding file. If you are still unable to resolve the error, you can contact the author of the file and explain the problem. Usually, the problem will be resolved after a few attempts.

You may try renaming your project to ‘cmake error: cannot determine link language for the target’ to avoid this problem. If you have a Chinese-language file, for example, you can rename it to Yi Si Shi Shuo Bu Que. For an English-language project, you should rename the files to /usr/local/GLFW/GLFW-3.2.1/examples. This should resolve the error and continue building.

In order to avoid this error, you should make sure that you install a compatible compiler. You should be able to download it for free. However, if you can’t, you can always hire someone who knows CMake. This will save you the trouble of debugging. You can also seek help from a friend who knows how to fix this problem. This article will teach you how to solve the error and avoid it.

The CMake Error: “Cannot determine link language for target” is a common problem with many projects. Regardless of whether you’re coding in English or in another language, you’ll need to use the right language to create the desired project. To fix the error, you’ll need to fix the linker’s link language. It will then be able to work properly and build your project.

When the CMake Error: “Cannot determine link language for target”, you should ensure that you’re using the correct language for your project. This will cause your project to be built in a specific language. Changing the linker’s config file will make the build fail, but you’ll need to use the right version to run it. This is a simple task and you’ll be able to work with your project in no time.

When you receive this error, it means that the CMake Error: “Cannot determine link language for target”. This error occurs when you’re trying to use a different language to compile your project. Therefore, you must use the right linker to create your project. In this case, the CMake Error: Cannot determine the links between target and source. If the error persists, try removing it.

If this error continues, you should try removing the files in question. If the error does not go away, try changing the linker language. The CMake Error: “Cannot determine link language for target” is a common problem when a project does not support a certain language. You need to choose a different one to make your project work properly. The build files should be in a directory named “examples” in order to build a game.

cmake error: Cannot determine link language for target. After a CMake Error: “Cannot determine link language for target” has occurred, it is important to fix the problem. The solution is simple. To solve this problem, simply remove the files from your project. The linker is responsible for linking your project in the correct language. If you’re using the wrong linker, you will need to change the build settings in your library to fix it.

Hey guys,

I’m attempting to run the pcl_visualizer_demo.cpp found here: http://pointclouds.org/documentation/…

I have taken the _demo off the .cpp file and in the CMakeLists.txt.

I ran:

 catkin_create_pkg pcl_visualizer roscpp std_msgs rospy

I then placed the pcl_visualizer.cpp in the catkin_ws/src/pcl_visualizer/src folder

this is my full CMakeLists.txt file, as specified by the tutorial linked above, with only the _demo removed from the appropriate places. (note that I still get the same error even with _demo being included and the package being named appropriately for that as well).

cmake_minimum_required(VERSION 2.6 FATAL_ERROR)

project(pcl_visualizer)

find_package(PCL 1.2 REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

add_executable (pcl_visualizer pcl_visualizer.cpp)
target_link_libraries (pcl_visualizer ${PCL_LIBRARIES})

When I run the catkin_make, I get this error:

CMake Error: CMake can not determine linker language for target: pcl_visualizer
CMake Error: Cannot determine link language for target "pcl_visualizer".

Does anyone have any suggestions as to what could be causing this?

Понравилась статья? Поделить с друзьями:
  • Clx 2160 ошибка датчика тонера
  • Clutch down ошибка скания
  • Cluster service on node did not reach the running state the error code is 0x5b4
  • Cluster physical disk resource encountered an error while attempting to terminate
  • Cluster error видеорегистратор