0

Compiling my C++ SDL2 project with a g++ using MinGW-w64 on Windows 10 is quite simple with the following command:
g++ main.c -o game.exe -lmingw32 -lSDL2main -lSDL2
But I can't seem to create an equivalent configuration with CMake.

This is how my CMakeList.txt file looks like (generated by CLion):

cmake_minimum_required(VERSION 3.7)
project(cfirst)

set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES main.cpp)
add_executable(cfirst ${SOURCE_FILES})

This fails compilation, citing multiple "undefined references", including an "undefined reference to `WinMain@16'", which I assume is caused by incorrectly compiling as 64bit.
This is identical to what happens if I omit the -lmingw32 -lSDL2main -lSDL2 options when using g++ directly.
How would I go about adding equivalent configuration to the CMakeList.txt file?

Acidic
  • 6,154
  • 12
  • 46
  • 80

1 Answers1

1

If linker can find the libs, this should work:

target_link_libraries(cfirst PRIVATE mingw32 SDL2main SDL2)
vatosarmat
  • 1,090
  • 10
  • 22