编译SDL( solution:SDL_image.h:undefined reference to `IMG_Load' )

安装好SDL后,用gcc编译时,在后面要加配置选项(注意:配置选项的标号是TAB键上面的那个键)

比如:gcc -o sdl SDL.c `sdl-config --cflags --libs`


sdl_config作用

Now that we've created an SDL application, we need to compileit. SDL
applications are easy to compile; assuming a proper installation ofSDL, they
require just a few flags and libraries. The standard SDLdistribution includes a

program called sdl-config (similar to the gtk-config andglib-config scripts
that ship with the GTK+ toolkit) for supplying the appropriatecommand-line
arguments to gcc. The command sdl-config --cflags produces a listof the
options that should be passed to the compiler, and sdl-config--libs
produces a list of libraries that should be linked in. Theseoptions allow SDL
applications to compile correctly regardless of the location orversion of the
library. The following command will correctly build an SDLapplication:

$ gcc sdltest.c -o sdltest `sdl-config --cflags --libs`

我们设计了一个sdl的应用程序,我们需要编译它,sdl应用程序很容易编译,假设我们已经有一个安装恰当的sdl程序,编辑就只是需要一些flags还有库函数,标准的sdl安装包含一个叫做sdl_config的程序,它的作用是为命令行提供gcc所需要的参数,命令sdl-config--cflags 产生一些编译所需要的可选项。同时sdl-config --libs产生需要被连接的函数。这些允许sdl的应用程序正确的编译,不需要考虑版本问题。一下的这个命令就可以正确的编译一个文件


注意:有可能会出现undefined reference to `IMG_Load',这是由于使用了SDL_image.h的定义的函数

gcc error:
----------------------------------------------------------------------
LoadPNG.c:(.text+0x45): undefined reference to`IMG_Load'
collect2: ld returned 1 exit status
----------------------------------------------------------------------
egg pain for an hour....

before:
I compile like this:
>> gcc -Wall hello.c -o hello
if I do not use the extension sdl , everything is fine,
however,when I try to load png jpg tif ... pictures , I haveto use the extension sdl modules,the compile error appears likewhat I had shown in the beginning of this article.
I search Internet,I found the same problem:
the solution is:
compile like following:
>>gcc -Wall hello.c -o hello  `sdl-config --cflags --libs` -lSDL_image
but you should not compilelike this:
>>gcc -Wall hello.c -o hello -lSDL -lSDL_image
the gcc donot know where isthe include file
you can try likefollowing
>>gcc -Wall hello.c -o hello -I /usr/include/SDL -lSDL -lSDL_image
then whatever extension you add ,just add -lSDL_XXXX ,theworld comes back again!


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值