2014-04-22 73 views
3
1 #include "SDL2/SDL.h" 

    3 
    4 int main(int argc, char* args[]) 
    5 { 
    6  SDL_Init(SDL_INIT_EVERYTHING); 

    8  SDL_QUIT(); 
    9  return 0; 
10 } 

我已經安裝SDL2在Debian倉庫和我運行在g ++上使用Linux上的SDL2?

g++ -o test.cpp a.out -lSDL2 

,我收到了一大堆的錯誤:

a.out:(.rodata+0x0): multiple definition of `_IO_stdin_used' 
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o:(.rodata.cst4+0x0): first defined here 
a.out: In function `data_start': 
(.data+0x8): multiple definition of `__dso_handle' 
/usr/lib/gcc/x86_64-linux-gnu/4.7/crtbegin.o:(.data+0x0): first defined here 
a.out: In function `_fini': 
(.fini+0x0): multiple definition of `_fini' 
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crti.o:(.fini+0x0): first defined here 
a.out: In function `_start': 
(.text+0x0): multiple definition of `_start' 
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o:(.text+0x0): first defined here 
a.out: In function `_init': 
(.init+0x0): multiple definition of `_init' 
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crti.o:(.init+0x0): first defined here 
a.out: In function `data_start': 
(.data+0x0): multiple definition of `__data_start' 
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o:(.data+0x0): first defined here 
/usr/lib/gcc/x86_64-linux-gnu/4.7/crtend.o:(.tm_clone_table+0x0): multiple definition of `__TMC_END__' 
a.out:(.data+0x10): first defined here 
/usr/bin/ld: error in a.out(.eh_frame); no .eh_frame_hdr table will be created. 
collect2: error: ld returned 1 exit status 

我已經試過

g++ test.cpp $(pkg-config --cflags --libs sdl2) 

並獲得:

test.cpp: In function ‘int main(int, char**)’: 
test.cpp:6:14: error: ‘(SDL_EventType)256u’ cannot be used as a function 

我不知道是什麼導致這些錯誤。 適當的頭文件存在於

的/ usr /包括/ SDL2/

目錄。難道我做錯了什麼?

回答

5

的頭必須是:<SDL2/SDL.h>
的退出功能:SDL_Quit();
命令:g++ teste.cpp -o filename -lSDL2

+0

這工作!謝謝 –

2

//錯誤:g++ -o test.cpp a.out -lSDL2

//好:g++ test.cpp -lSDL2(a.out的隱含的)

//更好:g++ test.cpp -g -pedantic -o test -lSDL2

我懷疑的主要問題可能只是一直把g ++參數的順序錯誤。

+0

'g ++ test.cpp -G -pedantic -o test -lSDL2' 「-G」命令無法識別 –

+0

嗨 - 我的壞。抱歉。小寫「-g」:'g ++ -g -Wall -pedantic test.cpp -o test -lSDL2' – FoggyDay