Answer the question
In order to leave comments, you need to log in
Clion+MinGW+SDL2+CMake?
Please help fix the error.
I threw the files from the SDL folder into the folder with MinGW
main.cpp
#include <iostream>
#include <SDL2/SDL.h>
#include <stdio.h>
//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
int main( int argc, char* args[] )
{
//The window we'll be rendering to
SDL_Window* window = NULL;
//The surface contained by the window
SDL_Surface* screenSurface = NULL;
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
}
else
{
//Create window
window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
if( window == NULL )
{
printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
}
else
{
//Get window surface
screenSurface = SDL_GetWindowSurface( window );
//Fill the surface white
SDL_FillRect( screenSurface, NULL, SDL_MapRGB( screenSurface->format, 0xFF, 0xFF, 0xFF ) );
//Update the surface
SDL_UpdateWindowSurface( window );
//Wait two seconds
SDL_Delay( 2000 );
}
}
//Destroy window
SDL_DestroyWindow( window );
//Quit SDL subsystems
SDL_Quit();
return 0; }
cmake_minimum_required(VERSION 3.12)
project(Pong)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIR})
set(CMAKE_CXX_STANDARD 17)
add_executable(Pong main.cpp)
target_link_libraries(${CMAKE_PROJECT_NAME} ${SDL2_LIBRARY} -lmingw32 -lSDL2main -lSDL2 -mwindows)
[ 50%] Linking CXX executable Pong.exe
CMakeFiles\Pong.dir/objects.a(main.cpp.obj): In function `SDL_main':
C:/Users/Ilya/CLionProjects/Pong/main.cpp:16: undefined reference to `SDL_Init'
C:/Users/Ilya/CLionProjects/Pong/main.cpp:18: undefined reference to `SDL_GetError'
C:/Users/Ilya/CLionProjects/Pong/main.cpp:23: undefined reference to ` SDL_CreateWindow'
C:/Users/Ilya/CLionProjects/Pong/main.cpp:26: undefined reference to `SDL_GetError'
C:/Users/Ilya/CLionProjects/Pong/main.cpp:31: undefined reference to `SDL_GetWindowSurface'
C: /Users/Ilya/CLionProjects/Pong/main.cpp:34: undefined reference to `SDL_MapRGB'
C:/Users/Ilya/CLionProjects/Pong/main.cpp:34: undefined reference to `SDL_FillRect'
C:/Users/Ilya/CLionProjects/Pong/main.cpp:37: undefined reference to `SDL_UpdateWindowSurface'
C:/Users/Ilya/CLionProjects/Pong/main.cpp:40: undefined reference to `SDL_Delay'
C:/Users /Ilya/CLionProjects/Pong/main.cpp:44: undefined reference to `SDL_DestroyWindow'
C:/Users/Ilya/CLionProjects/Pong/main.cpp:47: undefined reference to `SDL_Quit'
c:/mingw/bin/. ./lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `[email protected]'
collect2.exe : error: ld returned 1 exit status
CMakeFiles\Pong.dir\build.make:87: recipe for target 'Pong.exe' failed
mingw32-make.exe[3]: *** [Pong.exe] Error 1
mingw32- make.exe[2]: *** [CMakeFiles/Pong.dir/all] Error 2
CMakeFiles\Makefile2:71: recipe for target 'CMakeFiles/Pong.dir/all' failed
CMakeFiles\Makefile2:83: recipe for target 'CMakeFiles/Pong.dir/rule' failed
mingw32-make.exe[1]: *** [CMakeFiles/Pong.dir/rule] Error 2
mingw32-make.exe: *** [Pong] Error 2
Makefile:117: recipe for target 'Pong' failed
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question