I have the g++ compiler installed with MSYS2. In my CMake file, I have added the WIN32 flag to the add_executable
command. It works for MSVC and Clang, but not for g++. It gives me a linking error saying undefined reference to "WinMain"
. Is there some sort of flag that I need to pass to the compiler by using target_compile_options
?
EDIT: I think the problem is my entry point is wWinMain
instead of plain WinMain
.
EDIT2: My CMake files for reference:
Main CMake file
cmake_minimum_required(VERSION 3.22)
project(AlgorithmVisualizer)
add_subdirectory("AlgorithmVisualizer")
Project CMake file
cmake_minimum_required(VERSION 3.22)
add_executable(AlgorithmVisualizer WIN32
"src/AV/Application.cpp"
"src/AV/Application.hpp"
"src/AV/Main.cpp"
"src/AV/Window.cpp"
"src/AV/Window.hpp"
"src/AV/ErrorHandling.cpp"
"src/AV/ErrorHandling.hpp" "src/AV/Macros.hpp" "src/pch.hpp")
target_include_directories(AlgorithmVisualizer PRIVATE "deps/include")
target_compile_definitions(AlgorithmVisualizer PRIVATE $<$<CONFIG:Debug>:AV_DEBUG>)
target_precompile_headers(AlgorithmVisualizer PRIVATE "src/pch.hpp")
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory("deps/glfw")
add_subdirectory("deps/utfcpp")
add_subdirectory("deps/glad")
target_link_libraries(AlgorithmVisualizer glfw utf8::cpp glad Comctl32.lib)
target_compile_definitions(AlgorithmVisualizer PRIVATE UNICODE _UNICODE)
find_package(OpenGL REQUIRED)
target_link_libraries(AlgorithmVisualizer OpenGL::GL)
target_compile_features(AlgorithmVisualizer PUBLIC cxx_std_20)
if(MSVC)
target_compile_options(AlgorithmVisualizer PUBLIC /Zc:__cplusplus)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(AlgorithmVisualizer PUBLIC -municode)
endif()