質問

I've downloaded SDL2.0 like this:

~/tmp>wget http://www.libsdl.org/tmp/release/SDL2-2.0.0.tar.gz

Then I extracted it, went into the directory, and did ./configure && make && make install. Everything went fine. Now I've made a very simple sample (see far below). My problem is when I try to compile it doesn't work, So I copied SDL2.dll into the current directory and tried all combinations I know without success:

~/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

All errors are either:

/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

Or:

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

How would you do?

Here's my source code I try to compile:

#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;
 }
役に立ちましたか?

解決

Not sure if this will work for cygwin, but on my Mac using pkg-config I was able to find out the compiler flags:

gcc example.c $(pkg-config --cflags --libs sdl2)

他のヒント

you should link with this flags: -Lwhere/sdldll/is -lSDL2, and -Iwhere/sdlincludes/are

-L flag is where the binaries(dll and lib) are, and -l is the filename of the dll(or lib) -I flag is where the include files are located(.h)

gcc -o program.exe main.cpp -LSDL2/bin -lSDL2 -ISDL2/include
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top