Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SDL2 on linux with g++?

   #include "SDL2/SDL.h"


   int main(int argc, char* args[])
   {
       SDL_Init(SDL_INIT_EVERYTHING);

       SDL_QUIT();
       return 0;
  }

I have installed SDL2 through the debian repositories, and I am running

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

I get a whole lot of errors:

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

I have tried

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

and get:

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

I have no idea what is causing these errors. The proper header files are present in the

/usr/include/SDL2/

directory. Am I doing something wrong?

like image 254
RN_ Avatar asked Apr 22 '14 22:04

RN_


People also ask

What does G ++ command do in Linux?

g++ command is a GNU c++ compiler invocation command, which is used for preprocessing, compilation, assembly and linking of source code to generate an executable file.

What platforms does SDL2 support?

SDL supports Linux, Windows, Windows CE, BeOS, MacOS, Mac OS X, FreeBSD, NetBSD, OpenBSD, BSD/OS, Solaris, IRIX, and QNX. The code contains support for AmigaOS, Dreamcast, Atari, AIX, OSF/Tru64, RISC OS, SymbianOS, and OS/2, but these are not officially supported.


1 Answers

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

// Good: g++ test.cpp -lSDL2 (a.out implicit)

// Better: g++ test.cpp -g -pedantic -o test -lSDL2

I suspect the main problem might simply have been putting the g++ arguments in the wrong order.

like image 89
FoggyDay Avatar answered Sep 18 '22 02:09

FoggyDay