Linux动态库nm可以查询到符号,编译链接时候提示失败

kongslly 2016-08-17 11:45:47
现有一个动态库:
[root@localhost test]# ll /lib64/libplayer.so
-rwxr-xr-x 1 root kongs 19290 8月 16 20:30 /lib64/libplayer.so

使用nm查看如下:
[root@localhost test]# nm /lib64/libplayer.so | grep print_test
00000000000010a0 t print_test

现有测试代码:
int main()
{
printf("playTest\n");
print_test();
return 0;
}

Makefile文件如下:

CC=gcc
CFLAGS=-O3 -Wall -fmessage-length=0 -fPIC -DARCH_x86
OBJS=playerTest.o
LIBS+= -lplayer
TARGET= playerTest
$(TARGET):$(OBJS)
$(CC) -o $(TARGET) $(OBJS) $(CFLAGS) $(LIBS)
chmod 6755 $(TARGET)
all:$(TARGET)
install: all
chmod 6755 $(TARGET)
clean:
rm -f $(OBJS) $(TARGET)


编译提示如下:
[root@localhost test]# make clean
rm -f playerTest.o playerTest
[root@localhost test]# make
gcc -O3 -Wall -fmessage-length=0 -fPIC -DARCH_x86 -c -o playerTest.o playerTest.c
gcc -o playerTest playerTest.o -O3 -Wall -fmessage-length=0 -fPIC -DARCH_x86 -lplayer -lcua
playerTest.o: In function `main':
playerTest.c:(.text+0x13): undefined reference to `print_test'
collect2: ld 返回 1
make: *** [playerTest] 错误 1
[root@localhost test]#


这是什么原因?很奇怪
...全文
1101 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
fly 100% 2016-08-18
  • 打赏
  • 举报
回复
环境变量把路径加进去

23,217

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧