c++ - 将 32 位和 64 位 .so 文件与 g++ 链接为 c++ 程序

标签 c++ g++ 64-bit

我正在尝试为 C++ 程序同时链接 32 位和 64 位 .so 文件。 我正在使用 64 位 Ubuntu 12.04.1 我也没有要重新编译的源文件。

当我运行 g++ 命令时:

g++ onlineTraining.cpp -I /usr/local/MATLAB/R2012a_Student/extern/include/ -L /home/forest/SoarSuite/out/ -L /usr/local/MATLAB/R2012a_Student/bin/glnx86/ -I /home/forest/SoarSuite/out/include -leng -lmat -lmex -lut -lSoar

我得到以下输出,因为它无法识别 32 位 .so 文件:

/usr/bin/ld: skipping incompatible /usr/local/MATLAB/R2012a_Student/bin/glnx86//libeng.so when searching for -leng
/usr/bin/ld: cannot find -leng
/usr/bin/ld: skipping incompatible /usr/local/MATLAB/R2012a_Student/bin/glnx86//libmat.so when searching for -lmat
/usr/bin/ld: cannot find -lmat
/usr/bin/ld: skipping incompatible /usr/local/MATLAB/R2012a_Student/bin/glnx86//libmex.so when searching for -lmex
/usr/bin/ld: cannot find -lmex
/usr/bin/ld: skipping incompatible /usr/local/MATLAB/R2012a_Student/bin/glnx86//libut.so when searching for -lut
/usr/bin/ld: cannot find -lut
collect2: ld returned 1 exit status

当我使用 -m32 运行 g++ 命令时:

g++ -m32 onlineTraining.cpp -I /usr/local/MATLAB/R2012a_Student/extern/include/ -L /home/forest/SoarSuite/out/ -L /usr/local/MATLAB/R2012a_Student/bin/glnx86/ -I /home/forest/SoarSuite/out/include -leng -lmat -lmex -lut -lSoar

我得到以下输出,因为现在它无法识别 64 位 .so 文件:

/usr/bin/ld: skipping incompatible /home/forest/SoarSuite/out//libSoar.so when searching for -lSoar
/usr/bin/ld: cannot find -lSoar
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
collect2: ld returned 1 exit status

是否可以同时链接 34 位和 64 位 .so 文件? 谢谢。

最佳答案

不,这是不可能的。 32 位库只能链接到 32 位可执行文件,而 64 位库只能链接到 64 位可执行文件。

如果您尝试链接的 Matlab 库仅提供 32 位版本,您还需要将应用程序构建为 32 位版本(使用 -m32),然后链接仅 32 位库。

关于c++ - 将 32 位和 64 位 .so 文件与 g++ 链接为 c++ 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14271014/

相关文章:

C++ 编译器正在更改我的结构的对齐方式。我怎样才能防止这种情况发生?

c++ - 强制资源管理器重新加载注册表值

c++ - 如何测试 C++ 是否正在使用 openmp?

c++ - g++ 将字段的基本构造函数错误并忽略它的参数

linux - 为什么 strace 报告我的 x64 FASM 程序在 32 位模式下运行?

c++ - 在没有宏的情况下获取编译时日期和时间

c++ - <string.h> 和 <string> 之间的 VS2010 SP1 C++ STL 字符串运行时行为不同

c++ - 在非指针变量和类成员上放置 new

cocoa - 是否可以仅为 64 位 arch 构建 Mac App Store 应用程序?

c# - NGEN x86 与 x64 与 .NET 可执行文件