I am trying to learn and use SDL on my project. at first I had some problems where my ide can't find it. I'm using clion ide and mingw. I added the sdl on mingw (C:\\MinGW\\include\\SDL2) and now it's working. But still I can't compile. any idea about this error?
Linking C executable Hello_World.exe
CMakeFiles\Hello_World.dir/objects.a(main.c.obj): In function `SDL_main':
C:/Users/Deve/ClionProjects/Hello World/main.c:5: undefined reference to `SDL_Init'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libmingw32.a(main.o):(.text.startup+0xa7): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
this my only code for now
#include "SDL2/SDL.h"
int main(int argc, char *argv[]){
SDL_Init(SDL_INIT_VIDEO);
return 0;
}
and I can't make it working.
here is my cmake
cmake_minimum_required(VERSION 3.2)
project(Hello_World)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")
set(SOURCE_FILES main.c)
add_executable(Hello_World ${SOURCE_FILES})
my system is windows 8.1 64bit
Did you included .a and / or .lib ? If you don't include that, your program will never find the functions you want to use.
您应该在cmake文件中包含-lSDL
标志:
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -lSDL")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.