在 64 位 Linux armv8 计算机上编译 32 位二进制文件时遇到问题

Having trouble compiling 32-bit binary on 64-bit linux armv8 machine

本文关键字:二进制文件 遇到 问题 编译 Linux armv8 计算机      更新时间:2023-10-16

我正在尝试在Jetson Tx2上使用C ++ ARM 32位库,这是一台ARM 64位Linux机器。当我尝试编译库提供的一些示例代码时,出现以下编译错误:

/usr/bin/ld: skipping incompatible /home/nvidia/libroyale/bin/libroyale.so 
when searching for -lroyale
/usr/bin/ld: cannot find -lroyale
collect2: error: ld returned 1 exit status
CMakeFiles/sampleCameraInfo.dir/build.make:94: recipe for target  
'sampleCameraInfo' failed
make[2]: *** [sampleCameraInfo] Error 1
CMakeFiles/Makefile2:67: recipe for target  
'CMakeFiles/sampleCameraInfo.dir/all' failed
make[1]: *** [CMakeFiles/sampleCameraInfo.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

我假设此错误是因为 32 位库与 64 位机器不兼容。

我一直在浏览其他关于类似问题的 StackOverflow 论坛,并根据这些论坛的建议在编译时将 -m32 标志添加到 CXXFLAGS 和 LDFLAGS 中。但是,我随后收到以下错误:

g++: error: unrecognized command line option ‘-m32’
CMakeFiles/sampleCameraInfo.dir/build.make:62: recipe for target 
'CMakeFiles/sampleCameraInfo.dir/sampleCameraInfo.cpp.o' failed
make[2]: *** [CMakeFiles/sampleCameraInfo.dir/sampleCameraInfo.cpp.o]   Error 1
CMakeFiles/Makefile2:67: recipe for target 
'CMakeFiles/sampleCameraInfo.dir/all' failed
make[1]: *** [CMakeFiles/sampleCameraInfo.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

其他一些 StackOverflow 线程说,为了使用 -m32 标志,必须运行以下命令:

sudo apt-get install g++-multilib

我认为安装无法正常工作,因为我收到以下错误:

Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
g++-multilib:armhf : Depends: cpp:armhf (>= 4:5.3.1-1ubuntu1) but it is
not going to be installed
Depends: gcc-multilib:armhf (>= 4:5.3.1-1ubuntu1) but it is not going to be installed
Depends: g++:armhf (>= 4:5.3.1-1ubuntu1) but it is not going to be installed
Depends: g++-5-multilib:armhf (>= 5.3.1-3~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

任何建议将不胜感激。谢谢!

更新:我意识到 -m32 标志仅在 x86 Linux 机器上受支持。有谁知道ARM机器是否有一些等效物?

我看了一下 GCC 文档,尤其是在以下页面上:

https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/x86-Options.html

https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/AArch64-Options.html

看起来对于GNU编译器来说,x86是一种类型的CPU;你可以为这种CPU类型创建16位、32位或64位代码。

然而,对于GNU编译器来说,32位ARM CPU和64位ARM CPU是两种完全不同的CPU类型。

因此,使用 64 位 ARM 编译器编译 32 位 ARM 与使用 ARM 编译器编译 x86 相同:它不起作用。

当然,32位库不会被接受;ARM编译器也不会接受x86库。