c - ranlib 和静态库

标签 c linux gcc makefile x86-64

我正在尝试链接我创建的静态库,但出现此错误。

libmine.a: could not read symbols: Archive has no index; run ranlib to add one

我尝试执行 ranlib libmine.a 但没有任何改变,它仍然给出相同的错误。我该如何解决这个问题?

最佳答案

要查看存档中的符号,请使用 nm。

nm -s libmine.a

<输出>

子例程的入口点应标记为“T”,如

00000000 T _sub1
00000019 T _sub2

What switches did you use in "ar" to make the static library? I usually use "ar -r" as in

ar -r libmine.a mine.o yours.o

如果您仍然遇到问题,请添加“-s”选项

ar -s -r libmine.a mine.o yours.o

此外,请确保路径中没有其他“libmine.a”文件,或者为您的“libmine.a”创建一个明确的路径。链接器可能会选择不同的“libmine.a”。

关于c - ranlib 和静态库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11346240/

相关文章:

c - 为什么这个质因数分解算法有缺陷却给出了正确的答案?

c++ - 为什么在重定向 stdout 和 stdin 时 Python 的行为不符合预期?

c - 在 gcc 中编译 SHA1( ) 函数失败。 c语言

gcc - gfortran:尝试执行 'f951' 时出错:execvp:没有这样的文件或目录

c++ - 在 GDB 上编辑并继续

c++ - 无法使用 pthread_kill 和 sigwait 解锁/"wake up"线程

c - mmap 或 malloc 是否分配 RAM?

linux - 无法使用 makefile 进行编译 - 未定义对 `boost::re_detail 的引用

linux - IFS 和命令替换

linux - 在 shell 脚本中将脚本目录更改为用户的主目录