undefined reference to `WinMain'

I am currently trying to use the SDL2 program. I just have the basic program to set up the window right now, and it doesn't compile.

I am using CLion, and MinGW. It compiles simple programs but I cannot add in SDL2

ERRORS:

C:\Users\TreyG\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\171.4073.41\bin\cmake\bin\cmake.exe --build "C:\Users\TreyG\CLionProjects\Test Project\cmake-build-release" --target Test_Project -- -j 8
Scanning dependencies of target Test_Project
[ 50%] Building CXX object CMakeFiles/Test_Project.dir/main.cpp.obj
[100%] Linking CXX executable Test_Project.exe
CMakeFiles\Test_Project.dir\build.make:96: recipe for target 'Test_Project.exe' failed
CMakeFiles\Test_Project.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x1b): undefined reference to `SDL_Init'
CMakeFiles\Test_Project.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x4d): undefined reference to `SDL_CreateWindow'
CMakeFiles\Test_Project.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x60): undefined reference to `SDL_Delay'
CMakeFiles\Test_Project.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x65): undefined reference to `SDL_Quit'
CMakeFiles\Test_Project.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x72): undefined reference to `SDL_GetError'
C:/Code/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.3.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x2e): undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [Test_Project.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/Test_Project.dir/all] Error 2
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/Test_Project.dir/all' failed
mingw32-make.exe[1]: *** [CMakeFiles/Test_Project.dir/rule] Error 2
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/Test_Project.dir/rule' failed
Makefile:117: recipe for target 'Test_Project' failed
mingw32-make.exe: *** [Test_Project] Error 2
You need to add a reference to the SDL library.
Also you have created a Windows application instead of a console app. One way to fix this is to change your main() to
1
2
3
4
5
#include <windows.h>
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevIns, LPSTR lpszArgument, int iShow)
{
   // put your game code here
}


OR

change the project settinsg to console app.
That got rid of the Undefined reference to 'WinMain' but I still have the other errors.

Scanning dependencies of target Test_Project
[ 50%] Building CXX object CMakeFiles/Test_Project.dir/main.cpp.obj
[100%] Linking CXX executable Test_Project.exe
CMakeFiles\Test_Project.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x1b): undefined reference to `SDL_Init'
CMakeFiles\Test_Project.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x4d): undefined reference to `SDL_CreateWindow'
CMakeFiles\Test_Project.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x60): undefined reference to `SDL_Delay'
CMakeFiles\Test_Project.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x65): undefined reference to `SDL_Quit'
CMakeFiles\Test_Project.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x72): undefined reference to `SDL_GetError'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\Test_Project.dir\build.make:96: recipe for target 'Test_Project.exe' failed
mingw32-make.exe[3]: *** [Test_Project.exe] Error 1
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/Test_Project.dir/all' failed
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/Test_Project.dir/rule' failed
mingw32-make.exe[2]: *** [CMakeFiles/Test_Project.dir/all] Error 2
Makefile:117: recipe for target 'Test_Project' failed
mingw32-make.exe[1]: *** [CMakeFiles/Test_Project.dir/rule] Error 2
mingw32-make.exe: *** [Test_Project] Error 2

I have a lib folder in my project directory with the .a files. My CMakeLists.txt is as follows.

cmake_minimum_required(VERSION 3.7)
project(Test_Project)

set(CMAKE_CXX_STANDARD 11)

include_directories(${PROJECT_SOURCE_DIR}/include)
link_directories(${PROJECT_SOURCE_DIR}/lib)



set(SOURCE_FILES main.cpp)

add_executable(Test_Project ${SOURCE_FILES})
Nevermind, I forgot the target_link_libraries part...

Thanks for the help with the WinMain part though!!
Topic archived. No new replies allowed.