CMake unable to determine linker language with C++

后端 未结 10 1608
野趣味
野趣味 2020-11-28 06:41

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

相关标签:
10条回答
  • 2020-11-28 07:12

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

    0 讨论(0)
  • 2020-11-28 07:13

    In my case, implementing a member function of a class in a header file cause this error. Separating interface (in x.h file) and implementation (in x.cpp file) solves the problem.

    0 讨论(0)
  • 2020-11-28 07:18

    Try changing

    PROJECT(HelloWorld C)
    

    into

    PROJECT(HelloWorld C CXX)
    

    or just

    PROJECT(HelloWorld)
    

    See: http://www.cmake.org/cmake/help/v2.8.8/cmake.html#command:project

    0 讨论(0)
  • 2020-11-28 07:18

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

    0 讨论(0)
  • 2020-11-28 07:22

    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.

    0 讨论(0)
  • 2020-11-28 07:28

    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.

    0 讨论(0)
提交回复
热议问题