CMake unable to determine linker language with C++

后端 未结 10 1709
野趣味
野趣味 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:28

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

提交回复
热议问题