在VS和Cmake中使用main而不是wmain

时间:2018-08-14 09:16:14

标签: visual-studio cmake main wmain

我有以下CMakeLists.txt脚本:

# CMake entry point
cmake_minimum_required (VERSION 3.0)

#project name
project (PoorEngine)

#find OpenGL and include it, fail if OpenGl can't be found
find_package(OpenGL REQUIRED)

#create a variable and populate it with source files
set(
    SOURCES
    ${PROJECT_SOURCE_DIR}/Source/main.cpp
)

#create a variable and populate it with headers directories
set(
    HEADERS_DIR
    ${PROJECT_SOURCE_DIR}/ThirdParties/SDL/include
)

#explicit dependency libs
set(
    LIBRARIES_DIR
    ${PROJECT_SOURCE_DIR}/ThirdParties/SDL/Win32/
)

# Add an executable with the above sources
add_executable(${PROJECT_NAME} ${SOURCES}) 

#include headers directories in the target
target_include_directories(${PROJECT_NAME} PRIVATE ${HEADERS_DIR})

#add explicit dependency to SDL2
find_library(SDL_LIB NAMES SDL2 PATHS ${LIBRARIES_DIR})
target_link_libraries(${PROJECT_NAME} PRIVATE ${SDL_LIB})

add_custom_command(
    TARGET ${PROJECT_NAME} 
    POST_BUILD
    COMMAND 
        ${CMAKE_COMMAND} -E copy_if_different                   # which executes "cmake - E copy_if_different..."
        ${PROJECT_SOURCE_DIR}/ThirdParties/SDL/x64/SDL2.dll      # <--this is in-file
        $<TARGET_FILE_DIR:${PROJECT_NAME}>
)

我的main.cpp看起来像:

#include <SDL.h>

int main()
{
    SDL_Init(SDL_INIT_EVERYTHING);

    SDL_Delay(1000);

    SDL_Quit();
    return 0;
}

这会引起链接错误:

Error LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) Severity Code Description Project File Line Error LNK1120 1 unresolved externals

如果我使用wmain()代替main(),一切都会好起来,但我想坚持使用main()。我觉得我缺少一些设置,请帮助我。

0 个答案:

没有答案
相关问题