我已经下载了SDL2.0:
~/tmp>wget http://www.libsdl.org/tmp/release/SDL2-2.0.0.tar.gz
然后我解压缩它,进入目录,然后./configure && make && make install
。一切都很顺利。现在我做了一个非常简单的样本(见下文)。我的问题是,当我尝试编译它不起作用,所以我将SDL2.dll复制到当前目录并尝试了我知道的所有组合没有成功:
~/tmp/SDL2-2.0.0 >gcc -o tt tt.c -I/home/933012/tmp/SDL2-2.0.0/include -l SDL2.dll
~/tmp/SDL2-2.0.0 >gcc -o tt tt.c -I/home/933012/tmp/SDL2-2.0.0/include -lSDL2.dll
~/tmp/SDL2-2.0.0 >gcc -o tt tt.c -I/home/933012/tmp/SDL2-2.0.0/include -L SDL2.dll
~/tmp/SDL2-2.0.0 >gcc -o tt tt.c -I/home/933012/tmp/SDL2-2.0.0/include -LSDL2.dll
~/tmp/SDL2-2.0.0 >gcc -o tt tt.c -I/home/933012/tmp/SDL2-2.0.0/include -l SDL2
~/tmp/SDL2-2.0.0 >gcc -o tt tt.c -I/home/933012/tmp/SDL2-2.0.0/include -lSDL2
~/tmp/SDL2-2.0.0 >gcc -o tt tt.c -I/home/933012/tmp/SDL2-2.0.0/include -L SDL2
~/tmp/SDL2-2.0.0 >gcc -o tt tt.c -I/home/933012/tmp/SDL2-2.0.0/include -LSDL2
所有错误都是:
/usr/lib/gcc/i686-pc-cygwin/4.7.3/../../../../i686-pc-cygwin/bin/ld: cannot find -lSDL2.dll
collect2: error: ld returned 1 exit status
或者:
933012@F9ZW00118371 ~/tmp/SDL2-2.0.0 >gcc -o tt tt.c -I/home/933012/tmp/SDL2-2.0.0/include -LSDL2.dll
/cygdrive/c/Users/933012/AppData/Local/Temp/ccHZGVRX.o:tt.c:(.text+0xe): undefined reference to `SDL_Init'
/cygdrive/c/Users/933012/AppData/Local/Temp/ccHZGVRX.o:tt.c:(.text+0x42): undefined reference to `SDL_CreateWindow'
/cygdrive/c/Users/933012/AppData/Local/Temp/ccHZGVRX.o:tt.c:(.text+0x50): undefined reference to `SDL_GetWindowSurface'
/cygdrive/c/Users/933012/AppData/Local/Temp/ccHZGVRX.o:tt.c:(.text+0x67): undefined reference to `SDL_RWFromFile'
/cygdrive/c/Users/933012/AppData/Local/Temp/ccHZGVRX.o:tt.c:(.text+0x77): undefined reference to `SDL_LoadBMP_RW'
/cygdrive/c/Users/933012/AppData/Local/Temp/ccHZGVRX.o:tt.c:(.text+0x9c): undefined reference to `SDL_UpperBlit'
/cygdrive/c/Users/933012/AppData/Local/Temp/ccHZGVRX.o:tt.c:(.text+0xa7): undefined reference to `SDL_UpdateWindowSurface'
/cygdrive/c/Users/933012/AppData/Local/Temp/ccHZGVRX.o:tt.c:(.text+0xb2): undefined reference to `SDL_FreeSurface'
/cygdrive/c/Users/933012/AppData/Local/Temp/ccHZGVRX.o:tt.c:(.text+0xda): undefined reference to `SDL_PollEvent'
/cygdrive/c/Users/933012/AppData/Local/Temp/ccHZGVRX.o:tt.c:(.text+0xef): undefined reference to `SDL_DestroyWindow'
/cygdrive/c/Users/933012/AppData/Local/Temp/ccHZGVRX.o:tt.c:(.text+0xf4): undefined reference to `SDL_Quit'
/usr/lib/gcc/i686-pc-cygwin/4.7.3/../../../../i686-pc-cygwin/bin/ld: /cygdrive/c/Users/933012/AppData/Local/Temp/ccHZGVRX.o: bad reloc address 0x20 in section `.eh_frame'
/usr/lib/gcc/i686-pc-cygwin/4.7.3/../../../../i686-pc-cygwin/bin/ld: final link failed: Invalid operation
collect2: error: ld returned 1 exit status
你会怎么做?
这是我尝试编译的源代码:
#include <SDL.h>
int main(int argc, char *argv[]) {
int running;
SDL_Window *window;
SDL_Surface *windowsurface;
SDL_Surface *image;
SDL_Event event;
SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow("Hello World",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
592, 460, SDL_WINDOW_SHOWN);
windowsurface = SDL_GetWindowSurface(window);
image = SDL_LoadBMP("exampleimage.bmp");
SDL_BlitSurface(image, NULL, windowsurface, NULL);
SDL_UpdateWindowSurface(window);
SDL_FreeSurface(image);
running = 1;
while (running) {
while (SDL_PollEvent(&event) != 0) {
if (event.type == SDL_QUIT) {
running = 0;
break;
}
}
}
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
答案 0 :(得分:2)
不确定这是否适用于cygwin,但在我的Mac上使用pkg-config我能够找到编译器标志:
gcc example.c $(pkg-config --cflags --libs sdl2)
答案 1 :(得分:0)
你应该用这个标志链接: -Lwhere / sdldll / is -lSDL2 , -Iwhere / sdlincludes /
-L 标志是二进制文件(dll和lib)的位置, -l </ strong>是dll(或lib)的文件名 -I 标志是包含文件所在的位置(.h)
gcc -o program.exe main.cpp -LSDL2/bin -lSDL2 -ISDL2/include