Configuring SDL2 with Clion
Completed
Hello,
I'm new to CLion, i had some expierience with VisualC++, but mostly programmed in Java and Kotlin using IntelliJ. I'm trying to configure SDL2 with CLion and can't find any working solution. Currently i have recommended MinGW from Win-Builds installed (including SDL2), Find_SDL2.cmake file is in my cmake modules and here's my CMakeLists.txt:
cmake_minimum_required(VERSION 3.15)
project(SDLTest2)
set(CMAKE_CXX_STANDARD 11)
set(SDL2_PATH "C:\\dev\\SDL2")
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIR})
add_executable(SDLTest2 main.cpp)
target_link_libraries(SDLTest2 ${SDL2_LIBRARY})
Currently i'm getting an error:
c:/mingw/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x25): undefined reference to `WinMain'
I'm open to do everything from scratch, just want to get all of this to work.
Thanks in advance for any help.
Please sign in to leave a comment.
Hello!
Have you tried doing everything exactly as described here?
Yes i did, and that's where i'm currently at with it.
Have you downloaded SDL2 from https://www.libsdl.org/download-2.0.php? Why is your SDL2_PATH "C:\\dev\\SDL2" and not "C:\\dev\\SDL2-2.0.10\\i86_64-w64-mingw32", for example?
Do you have the message that SDL is found in the CMake tool window (View | Tool Windows | CMake)?
Yes, i downloaded it from there, just changed the folder name for clarity.
I had the message a while ago, but now it's:
"D:\Tools\CLion\CLion 2019.2.5\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\JJBla\CLionProjects\test
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/JJBla/CLionProjects/test/cmake-build-debug-mingw
[Finished]
I don't know why it's not there anymore.
Do you use i686-w64-mingw32 or x86_64-w64-mingw32 SDL2 distribution?
I use x86_64-w64-mingw32. I started from scratch with a new project and now it actually says "Found SDL2: mingw32;-mwindows;C:/dev/SDL2/lib/libSDL2main.a;C:/dev/SDL2/lib/libSDL2.dll.a". But it still dosen't work with the same errors appearring.
The thing is the issue most probably is not CLion-related. I assume if you try to build your CMake project in the Command Prompt, you'll get the same error. Is it so?
I would advice to try using i686-w64-mingw32 (just in case). And maybe ask on some SDL or CMake forums, or Stack Overflow.
Ok, thank for you your help. I haven't tried to complie cmake project but i compiled my program from command line just using g++ and it actually worked.
Please let me know if you find out that the CMake project can be built successfully outside CLion.
After some tries I finnaly got it working by removing both sdl2 and minGW and using the ones from msys2.