LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 956|回复: 4

请教问题啊,连接出错,怎么回事啊?

[复制链接]
发表于 2004-5-26 14:08:57 | 显示全部楼层 |阅读模式
以下这个程序(不过问题不在源码上,不必看):

#include "SDL.h" /* All SDL App's need this */
#include <stdio.h>

int main() {
   
    printf("Initializing SDL.\n");
   
    /* Initialize defaults, Video and Audio */
    if((SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)==-1)) {
        printf("Could not initialize SDL: %s.\n", SDL_GetError());
        exit(-1);
    }

    printf("SDL initialized.\n");

    printf("Quiting SDL.\n");
   
    /* Shutdown all subsystems */
    SDL_Quit();
   
    printf("Quiting....\n");

    exit(0);
}


编译后如下,是怎么回事啊?
/usr/local/SDL是头文件所在,/usr/local/lib是库所在。
第一步是成功的。

[b@d6-414-xgh c]$ gcc  -I/usr/local/include/SDL -c sdl.c
[b@d6-414-xgh c]$ gcc  -L/usr/local/lib -o sdl sdl.o
sdl.o(.text+0x26): In function `main':
: undefined reference to `SDL_Init'
sdl.o(.text+0x39): In function `main':
: undefined reference to `SDL_GetError'
sdl.o(.text+0x79): In function `main':
: undefined reference to `SDL_Quit'
collect2: ld returned 1 exit status
[b@d6-414-xgh c]$
发表于 2004-5-26 19:38:52 | 显示全部楼层

please link against SDL library

gcc -L/usr/local/lib -lSDL -o sdl sdl.o
 楼主| 发表于 2004-5-27 15:16:20 | 显示全部楼层

谢谢

连接没问题了,但运行出错了。
[b@d6-414-xgh c]$ gcc  -L/usr/local/lib -lSDL -o sdl sdl.o
[b@d6-414-xgh c]$ ./sdl
Initializing SDL.
./sdl: relocation error: /usr/lib/libSDL-1.2.so.0: undefined symbol: pthread_mutexattr_init
[b@d6-414-xgh c]$
[b@d6-414-xgh c]$
 楼主| 发表于 2004-5-27 17:15:14 | 显示全部楼层

用ldd显示如下,不知怎么回事。

[b@d6-414-xgh c]$ ldd sdl
        libSDL-1.2.so.0 => /usr/lib/libSDL-1.2.so.0 (0x40026000)
        libc.so.6 => /lib/tls/libc.so.6 (0x42000000)
        libm.so.6 => /lib/tls/libm.so.6 (0x4009e000)
        libdl.so.2 => /lib/libdl.so.2 (0x400c0000)
        libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0x400c3000)
        libXext.so.6 => /usr/X11R6/lib/libXext.so.6 (0x401a2000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
[b@d6-414-xgh c]$
 楼主| 发表于 2004-5-29 23:58:44 | 显示全部楼层

知道了,可能这样.

原来我本来装有SDL了,现在又装了一个.虽然我指定 -L/usr/local/lib 但它仍然连接到 /usr/lib上去.可能那个太旧了.而我头文件用的是新的.所以不行.我把 /usr/lib下的SDL删了.就好了.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表