我最近搬到了linux,而我在使用gcc編譯SDL C程序時遇到了問題。gcc不會編譯SDL C程序(對SDL函數的未定義引用)
我使用的命令:
gcc `sdl-config --cflags --libs` -o main main.c
即使通過SDL分隔條件,配置標誌:
gcc `sdl-config --cflags` -c main.c
gcc `sdl-config --libs` -o main main.o
我得到了同樣的錯誤:
/tmp/ccHYyjKd.o: In function `main':
main.c:(.text+0xe): undefined reference to `SDL_SetMainReady'
main.c:(.text+0x18): undefined reference to `SDL_Init'
main.c:(.text+0x31): undefined reference to `SDL_SetVideoMode'
main.c:(.text+0x54): undefined reference to `SDL_MapRGB'
main.c:(.text+0x6b): undefined reference to `SDL_FillRect'
main.c:(.text+0x77): undefined reference to `SDL_Flip'
main.c:(.text+0x83): undefined reference to `SDL_WaitEvent'
main.c:(.text+0x90): undefined reference to `SDL_Quit'
collect2: error: ld returned 1 exit status
我很簡單的程序:
#include <stdio.h>
#include <stdlib.h>
#define SDL_MAIN_HANDLED
#include <SDL/SDL.h>
int main()
{
// SDL Initialize
SDL_SetMainReady();
SDL_Init(SDL_INIT_VIDEO);
// Screen Initialize
SDL_Surface *screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
Uint32 screenColor = SDL_MapRGB(screen->format, 255, 255, 255);
SDL_FillRect(screen, NULL, screenColor);
SDL_Flip(screen);
// Main Program Loop
SDL_Event event;
do
{
SDL_WaitEvent(&event);
} while (event.type != SDL_QUIT);
// SDL Quit
SDL_Quit();
return 0;
}
我得到這個錯誤'在/ usr /斌/勞工處:找不到-lsdl' – rullof
你安裝sdl開發包?你使用哪種操作系統? – sujin
是的,我做到了。我如何檢查它是否安裝成功? – rullof