【问题标题】:CMake can not determine linker language for target - C++CMake 无法确定目标的链接器语言 - C++
【发布时间】:2020-04-15 17:41:51
【问题描述】:

我正在尝试开发一个供私人使用的引擎,我正在使用 CMake,因为我打算在未来使它成为多平台,但是开始出现一个我以前从未遇到过的错误,我试图更改项目( IEngine)到项目(IEngine CXX),如堆栈溢出的其他问题中所述,但错误仍然存​​在,这是我的 CMakeLists

cmake_minimum_required(VERSION 3.16.2)

project(IEngine)

find_package(Vulkan REQUIRED)

file(GLOB_RECURSE SRC_RENDERER
    "${IEngine_SOURCE_DIR}/src/Renderer/*.cpp"
    "${IEngine_SOURCE_DIR}/src/Renderer/*.hpp"
    "${IEngine_SOURCE_DIR}/src/Renderer/*.h")

source_group("Renderer" FILES ${SRC_RENDERER})

add_library(IEngine STATIC ${SRC_RENDERER})

if(WIN32)
    target_compile_definitions(IEngine PRIVATE VK_USE_PLATFORM_WIN32_KHR)
endif()

target_include_directories(IEngine PRIVATE Vulkan::Vulkan)
target_link_libraries(IEngine Vulkan::Vulkan)

输出:

Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.18363.
The C compiler identification is MSVC 19.24.28315.0
The CXX compiler identification is MSVC 19.24.28315.0
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe - works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe - works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
Found Vulkan: A:/VulkanSDK/1.2.131.1/Lib/vulkan-1.lib  
Configuring done
CMake Error: CMake can not determine linker language for target: IEngine
Generating done

【问题讨论】:

  • CMake 根据源文件确定链接器语言。您的库似乎没有源文件。 (阅读:SRC_RENDERER 变量为 empty)。这可能是您调试过程的起点。您始终可以使用message() 打印变量的值。

标签: c++ windows visual-studio cmake


【解决方案1】:

我多次遇到此错误 :( 将此添加到您的 CMakeLists.txt 中:

set_target_properties(IEngine PROPERTIES LINKER_LANGUAGE CXX)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-06
    • 1970-01-01
    • 2019-03-26
    • 1970-01-01
    • 2012-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多