【问题标题】:Errors compiling SDL2 code编译 SDL2 代码时出错
【发布时间】:2016-07-26 02:35:03
【问题描述】:

我正在尝试学习 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)

【问题讨论】:

  • #TARGETS specifies source files to be compiled 实际上没有,但指定目标。
  • 你有自己的标题吗?你忘了一个头后卫吗?
  • 您尝试与 libsdl 链接的 sdl 文件是什么?它是从哪里来的?源代码是否保存在该文件中?如果是这样 - 它只是提出问题,-w 向编译器保证你确实想要这些问题。

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


【解决方案1】:

我不太清楚这个错误是什么意思,但你似乎在编译时链接了错误的文件。

既然你问了,我可以告诉你我是如何在 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

【讨论】:

    猜你喜欢
    • 2011-01-22
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    相关资源
    最近更新 更多