1

I've been trying to get SDL2 to link with my project but I think my cmake file is no good. I get this error

====================[ Build | Chip_8_Interpreter | Debug ]======================
"C:\Program Files\JetBrains\CLion 2018.3.4\bin\cmake\win\bin\cmake.exe" --build "D:\Dropbox\Programming\Chip-8 Interpreter\cmake-build-debug" --target Chip_8_Interpreter -- -j 4
[ 50%] Linking CXX executable Chip_8_Interpreter.exe
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [Chip_8_Interpreter.exe] Error 1
CMakeFiles\Chip_8_Interpreter.dir\build.make:87: recipe for target 'Chip_8_Interpreter.exe' failed
mingw32-make.exe[2]: *** [CMakeFiles/Chip_8_Interpreter.dir/all] Error 2
CMakeFiles\Makefile2:71: recipe for target 'CMakeFiles/Chip_8_Interpreter.dir/all' failed
mingw32-make.exe[1]: *** [CMakeFiles/Chip_8_Interpreter.dir/rule] Error 2
CMakeFiles\Makefile2:83: recipe for target 'CMakeFiles/Chip_8_Interpreter.dir/rule' failed
mingw32-make.exe: *** [Chip_8_Interpreter] Error 2
Makefile:117: recipe for target 'Chip_8_Interpreter' failed

And currently my CMakeLists.txt looks like this

cmake_minimum_required(VERSION 3.14)
project(Chip_8_Interpreter)

set(CMAKE_CXX_STANDARD 14)

# include cmake/FindSDL2.cmake
set(SDL2_PATH "C:\\SDL2-2.0.12\\i686-w64-mingw32")
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIR})

add_executable(Chip_8_Interpreter main.cpp)
target_link_libraries(Chip_8_Interpreter ${SDL2_LIBRARY} -lmingw32 -lSDL2main -lSDL2 -mwindows)

And my main.cpp is just the basic SDL example. I've also recently installed MinGW and SDL2, so they should both be the newest stable release.

Van-Sama
  • 1,154
  • 4
  • 14
  • 21
  • Have you checked [this answer](https://stackoverflow.com/a/46460011/3440745) for the similar error message? If adding `#define SDL_MAIN_HANDLED` doesn't help, then show (add to the question post) your `main.cpp`. – Tsyvarev Aug 28 '20 at 06:21

0 Answers0