博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
libtest.a: could not read symbols: Archive has no index; run ranlib to add one的原因和解决方案
阅读量:4142 次
发布时间:2019-05-25

本文共 888 字,大约阅读时间需要 2 分钟。

        最近写makefile, 在main.cpp链接libtest.a的时候, 遇到了这个问题:libtest.a: could not read symbols: Archive has no index; run ranlib to add one, 百思不得其解, 怎么会有问题呢?  在网上找了下, 众说纷纭, 有的说g++版本不对, 有的说32位/64位不兼容, 各种说法都有。 而我的情况, 显然不是网上给出的情况。

        初步怀疑, 可能是libtest.a出了问题。 前面我们说过, 静态库实际上就是目标文件的集合, 于是乎从libtest.a中, 用ar命令解出test.o文件, 对test.o进行分析, 发现:

xxxxxx:~/mkfile> ar -x libtest.a xxxxxx:~/mkfile> lslibtest.a  main.cpp  test.cpp  test.h  test.oxxxxxx:~/mkfile> xxxxxx:~/mkfile> xxxxxx:~/mkfile> file test.otest.o: GCC precompiled header (version 013) for C++xxxxxx:~/mkfile> xxxxxx:~/mkfile> nm test.onm: test.o: File format not recognizedxxxxxx:~/mkfile>
        擦, test.o居然出了问题, 再看看test.o的生成过程, 果然就明白了。 原来我是这样生成的:

g++ -c test.cpp test.h -o test.o
       呵呵哒, 多了test.h,  去掉就OK.  这个问题, 我们在之前的博文说过, 故不再赘述。

       libtest.a: could not read symbols: Archive has no index; run ranlib to add one 的问题, 还是第一次见, 算是长见识了。 记忆结论只能增长经验, 学会分析, 找出问题原因并解决, 才能提高能力。

转载地址:http://wiwti.baihongyu.com/

你可能感兴趣的文章
乱七八糟的注意点们
查看>>
【转载】css实现三角形。]
查看>>
c# 数组定义 新增 填充 数据
查看>>
js实现 一些数学公式(待补充)
查看>>
JavaScript不要直接console.log打印数组 、 求线段交点
查看>>
有关webpack、 prototype 属性
查看>>
【有关npm】 watchify 、browserify
查看>>
Leaflet
查看>>
numpy常用操作
查看>>
CNN简单例子 MNIST手写识别数据集
查看>>
在 Windows Terminal(WT) 里配置anaconda命令行环境
查看>>
Google Colab 【详细 初次使用教程】
查看>>
ModuleNotFoundError: No module named ‘matplotlib.pyplot‘
查看>>
word embedding + 实战小技巧
查看>>
自己定义的向量插入和删除数据
查看>>
欢迎使用CSDN-markdown编辑器
查看>>
今天我在Codewars做的第一道题
查看>>
以后请每天做一个codewars好吗。
查看>>
最近学了栈,和一些心情emmm,11.11
查看>>
0129今天讲了贪心-教室问题*2 我没怎么听懂
查看>>