c++ 64位-无法读取符号:存档没有索引;执行ranlib命令添加
C++ 64 bits - could not read symbols: Archive has no index; run ranlib to add one
我正在尝试使用静态库在Linux RHAS 5.3 64位上生成一个非常简单的二进制文件。
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=%dn",x);
return 0;
}
如果我用32位编译,没有问题:
——(0931:结婚,06年4月11:$),g + +两个同伴m32 - wall - c ctest1.cpp
——(0931:Wed,06 Apr 11:$)——file ctest1.o
ctest1。0: ELF 32位LSB可重定位,Intel 80386,版本1 (SYSV),不剥离
——(0931:Wed,06 Apr 11:$)——ar -cvq libctest。一个ctest1.o
a - ctest1. 0
——(09031:Wed,06 Apr 11:$)——g++ -m32 - 0 prog.cpp libctest.a
——(0931:Wed,06 Apr 11:$)——./prog .
Valx = 5
但是,如果我尝试在64位编译,它会在链接期间失败,并出现错误"could not read symbols: Archive has no index;运行ranlib添加一个":
——(0933:结婚,06年4月11:美元)——g++ - wall - m64 - c ctest1.cpp
——(0935:Wed,06 Apr 11:$)——file ctest1.o
ctest1。0: ELF 64位LSB可重定位,AMD x86-64,版本1 (SYSV),不剥离
——(0933:Wed,06 Apr 11:$)——ar -cvq libctest。一个ctest1.o
a - ctest1. 0
——(0935:Wed,06 Apr 11:$)——g++ -m64 - 0 prog.cpp libctest.a
libctest。a:无法读取符号:档案没有索引;执行ranlib命令添加
collect2: ld返回1退出状态
在libtest上运行ranlib。A不改变任何东西
我的Linux版本如下
——(0937:Wed,06 Apr 11:$)——uname -a
Linux dev1 2.6.18-128。el5 #1 SMP星期三十二月17 11:41:38 EST 2008 x86_64 x86_64 x86_64 GNU/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, AMD x86-64, version 1 (SYSV), not stripped
prog.o: ELF 64-bit LSB relocatable, AMD x86-64, version 1 (SYSV), 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, Intel 80386, version 1 (SYSV), not stripped
prog.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), 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, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, 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
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- 数组索引的值没有增加
- C++,系统无法执行指定的程序
- 使用C++中的模板和运算符重载执行矩阵运算
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 芬威克树(BIT).找到具有给定累积频率的最小索引,单位为 O(logN)
- 执行函数时导致崩溃的变量
- 无论条件是否为true,if总是在c++中执行
- 当函数模板参数是具有默认参数的类模板时,函数模板参数的推导如何执行
- 在C++中对T*类型执行std::move的意外行为
- 查找最接近的大于当前数字的数字的索引
- 我们可以使用Back() - 值索引在其上执行向量插入
- 通过我的可执行文件的资源 ID 获取图标索引,C++
- 在C++中,执行去引用和获取索引0的操作是相同的
- C++数据结构来执行索引列表
- 如何在Eigen中执行索引操作
- 如何从数组执行索引搜索
- 如何执行索引搜索方法
- 试图对字符串执行索引搜索
- c++ 64位-无法读取符号:存档没有索引;执行ranlib命令添加