C&C++   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了C 64位 – 无法读取符号:存档没有索引;运行ranlib添加一个大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图使用静态库在 Linux RHAS 5.3 64bits上生成一个非常简单的二进制文件.

test1.cpp,其结果.o将嵌入到静态库中.

void ctest1(int *i)
{
   *i=5;
}

和prog.cpp

#include <stdio.h>
void ctest1(int *);

int main()
{
   int x;
   ctest1(&x);
   printf("Valx=%d\n",x);

   return 0;
}

如果我编译32位,没问题:

但是,如果我尝试以64位进行编译,则在链接期间失败,错误“无法读取符号:存档没有索引;运行ranlib添加一个”:

在libctest.a上运行ranlib不会改变任何东西.

我的Linux版本如下

有没有人知道问题的来源?

谢谢.

解决方法

在使用64位构建重新编译之前是否删除了库?

你的编译顺序对我有用:

$g++ -m64 -Wall -c prog.cpp
$g++ -m64 -Wall -c test1.cpp
$ar -cvq libtest.a test1.o
a - test1.o
$g++ -m64 -Wall -o prog1 prog.o libtest.a
$file test1.o prog.o
test1.o: ELF 64-bit LSB relocatable,not stripped
prog.o: ELF 64-bit LSB relocatable,not stripped
$./prog1
Valx=5
$

当我编译32位时:

$g++ -m32 -Wall -c prog.cpp
$g++ -m32 -Wall -c test1.cpp
$file test1.o prog.o
test1.o: ELF 32-bit LSB relocatable,not stripped
prog.o:  ELF 32-bit LSB relocatable,not stripped
$ar -cvq libtest.a test1.o
a - test1.o
$g++ -m32 -Wall -o prog1 prog.o libtest.a
/usr/bin/ld: warning: i386:x86-64 architecture of input file `libtest.a(test1.o)' is incompatible with i386 output
$file prog1
prog1: ELF 32-bit LSB executable,for GNU/Linux 2.6.9,dynamically linked (uses shared libs),not stripped
$./prog1
Memory fault 
$

这是一些RHEL 5版本(不是当前版本):

Linux toru 2.6.18-128.el5 #1 SMP Wed Dec 17 11:41:38 EST 2008 x86_64 x86_64 x86_64 GNU/Linux

我的GCC是版本4.1.2.我的AR版本如下,RANLIB打印相同的版本:

GNU ar 2.17.50.0.6-9.el5 20061020

我不需要直接使用ranlib.

大佬总结

以上是大佬教程为你收集整理的C 64位 – 无法读取符号:存档没有索引;运行ranlib添加一个全部内容,希望文章能够帮你解决C 64位 – 无法读取符号:存档没有索引;运行ranlib添加一个所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: