编译SDL2代码的错误

时间:2016-07-26 02:35:04

标签: c++ gcc compiler-errors g++ sdl-2

我正在尝试关注Lazy Foo的SDL2教程:http://lazyfoo.net/tutorials/SDL/01_hello_SDL/index2.php

我已经完成了教程,并且在执行程序时出现了我的窗口,即使在编译教程代码时遇到很多编译错误。当我使用g ++编译器时,错误是:

g++ sdl -w -lSDL2

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

我不知道这些编译错误意味着什么或如何解决它们。我尝试使用gcc编译器,但出现了相同的错误。有人可以帮我学习如何正确编译SDL2代码吗?我的错是什么?我的Makefile如下:

# CC specifies which compiler we're using
CC = g++

# C_FLAGS specifies addicional compiler flags
CFLAGS = -w -lSDL2

#TARGETS specifies source files to be compiled
TARGETS = sdl

all: $(TARGETS)
    $(CC) $(TARGETS) $(CFLAGS)

clean:
    rm -f $(TARGETS)

1 个答案:

答案 0 :(得分:0)

我不太清楚错误的含义,但看起来你在编译时会链接错误的文件。

因为您问我可以告诉您如何在Ubuntu 14.04 LTS中编译C程序。 (我只使用文本编辑器和终端)

这是命令:

$gcc main.c -o outputfile -lSDL2_image -lSDL2_mixer \`sld2-config --cflags --libs`

-lSDL2_image: library for image handling
-lSDL2_mixer: library for audio handling