当代码似乎没有问题时,我如何修复Clion中的链接器错误



所以,我没有代码,只有空文件和一个CMake,但我一直收到Linker错误。有人能详细解释一下我的问题是什么吗?我得到的一些信息是,我应该使用Visual Studio 2015作为我的编译器和其他东西,我想我已经设置好了。

错误:

[100%] Linking CXX executable DebugCinderGameCinderGame.exe
NMAKE : fatal error U1077: '"C:Program FilesJetBrainsCLion 2020.2.3bincmakewinbincmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:Program Files (x86)Microsoft Visual Studio 14.0VCBINnmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:Program Files (x86)Microsoft Visual Studio 14.0VCBINnmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:Program Files (x86)Microsoft Visual Studio 14.0VCBINnmake.exe"' : return code '0x2'
Stop.
LINK Pass 1: command "C:PROGRA~2MICROS~1.0VCbinlink.exe /nologo @CMakeFilesCinderGame.dirobjects1.rsp /out:DebugCinderGameCinderGame.exe /implib:CinderGame.lib /pdb:C:UserscesarDocumentsGitHubfinal-project-cesarmonsaludcmake-build-debugDebugCinderGameCinderGame.pdb /version:0.0 /machine:X86 /debug /INCREMENTAL /subsystem:windows /NODEFAULTLIB:LIBCMT /NODEFAULTLIB:LIBCPMT -LIBPATH:C:UserscesarDesktopcinder_0.9.2_vc2015libmswx86 C:UserscesarDesktopcinder_0.9.2_vc2015libmswx86Debugv140cinder.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFilesCinderGame.dir/intermediate.manifest CMakeFilesCinderGame.dir/manifest.res" failed (exit code 1120) with the following output:
LIBCMTD.lib(exe_winmain.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
DebugCinderGameCinderGame.exe : fatal error LNK1120: 1 unresolved externals

代码:

cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
set(CMAKE_CXX_STANDARD 11)
project(Connect4)
# This tells the compiler to not aggressively optimize and
# to include debugging information so that the debugger
# can properly read what's going on.
set(CMAKE_BUILD_TYPE Debug)
# Let's ensure -std=c++xx instead of -std=g++xx
set(CMAKE_CXX_EXTENSIONS OFF)
# Let's nicely support folders in IDE's
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Warning flags
if(MSVC)
# warning level 3 and all warnings as errors
add_compile_options(/W3)
else()
# lots of warnings and all warnings as errors
add_compile_options(-Wall -Wpedantic -Werror)
endif()
# FetchContent added in CMake 3.11, downloads during the configure step
include(FetchContent)
# FetchContent_MakeAvailable was not added until CMake 3.14
if(${CMAKE_VERSION} VERSION_LESS 3.14)
include(cmake/add_FetchContent_MakeAvailable.cmake)
endif()
FetchContent_Declare(
catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG devel
)
# Adds Catch2 testing library
FetchContent_GetProperties(catch2)
if(NOT catch2_POPULATED)
FetchContent_Populate(catch2)
add_library(catch2 INTERFACE )
target_include_directories(catch2 INTERFACE ${catch2_SOURCE_DIR}/single_include)
endif()
get_filename_component(CINDER_PATH "C:/Users/cesar/Desktop/cinder_0.9.2_vc2015" ABSOLUTE)
get_filename_component(APP_PATH "${CMAKE_CURRENT_SOURCE_DIR}/" ABSOLUTE)
include("${CINDER_PATH}/proj/cmake/modules/cinderMakeApp.cmake")
list(APPEND CORE_SOURCE_FILES
)
list(APPEND SOURCE_FILES    ${CORE_SOURCE_FILES}
include/core/Connect4.h
include/visualizer/FinalProjectApp.h
src/core/Connect4.cpp
src/visualizer/FinalProjectApp.cpp
)
list(APPEND TEST_FILES tests/Connect4Tests.cpp)
ci_make_app(
APP_NAME        CinderGame
CINDER_PATH     ${CINDER_PATH}
SOURCES         apps/cinder_game.cpp ${SOURCE_FILES}
INCLUDES        include
)
ci_make_app(
APP_NAME        ConsoleGame
CINDER_PATH     ${CINDER_PATH}
SOURCES         apps/main_console_game.cpp ${SOURCE_FILES}
INCLUDES        include
)
ci_make_app(
APP_NAME        GameTest
CINDER_PATH     ${CINDER_PATH}
SOURCES         tests/Connect4Tests.cpp ${SOURCE_FILES} ${TEST_FILES}
INCLUDES        include
LIBRARIES       catch2
)

if(MSVC)
set_property(TARGET GameTest APPEND_STRING PROPERTY LINK_FLAGS " /SUBSYSTEM:CONSOLE")
endif()

罪魁祸首可能是:

if(MSVC)
set_property(TARGET GameTest APPEND_STRING PROPERTY LINK_FLAGS " /SUBSYSTEM:CONSOLE")
endif()

这告诉链接器为控制台子系统构建,该子系统没有隐式WinMain函数:如果需要控制台构建,则必须自己编写一个。

如果您不需要控制台构建,可以将其更改为/SUBSYSTEM:WINDOWS,并且MFC将提供WinMain。

最新更新