静态库符号不被使用-l竟然发现 [英] Static library symbols not being found even with -l

查看:648
本文介绍了静态库符号不被使用-l竟然发现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个静态库,liborc-0.4.a没有共享库。我有依赖于liborc-0.4.a符号另一个库,libschroedinger-1.0.a(不共享)。如果我运行liborc-0.4.a纳米,如orc_init符号显示为T(意思是它们被定义)。我建libschroedinger-1.0.a与-lorc-0.4,因此看到的符号和是确定的命令行标志。

I have a static library, liborc-0.4.a with no shared library. I have another library, libschroedinger-1.0.a (no shared) that depends on symbols in liborc-0.4.a. If I run nm on liborc-0.4.a, symbols such as orc_init show up as T (meaning they are defined). I built libschroedinger-1.0.a with the command line flag -lorc-0.4 so it saw the symbols and was ok.

不过,现在我有一个小的可执行文件,它取决于libschroedinger-1.0.a。它编译罚款,但是当我运行链接 GCC -lschroedinger-1.0 -lorc-0.4输出-o input.o 它给出了错误,例如:

However, now I have a small executable that depends on libschroedinger-1.0.a. It compiles fine, but when I run the linker gcc -lschroedinger-1.0 -lorc-0.4 -o output input.o It gives errors such as:

/usr/local/lib/libschroedinger-1.0.a(libschroedinger_1.0_la-schro.o):schro.c :(文字+ 0×21):未定义的参考`orc_init

我该如何解决这个问题?感谢名单。

How can I fix this? Thanx.

推荐答案

GCC 是库的顺序敏感。当它编译 liborc-0.4.a 中,没有必要为 orc_init ,所以它不包括在内。解决的办法是把 LDFLAGS 在命令的末尾:

gcc is sensitive to the order of libraries. When it's compiling liborc-0.4.a in, there is no need for orc_init, so it's not included. The solution is to put the LDFLAGS at the end of the command:

gcc -o output input.o -lschroedinger-1.0 -lorc-0.4

这篇关于静态库符号不被使用-l竟然发现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆