在编译时跳过不兼容的库

kel*_*unn 34 c++ 64-bit 32-bit compilation conflicting-libraries

当我尝试在我的本地机器上编译我的项目的副本时,我收到一个错误,指出它正在跳过不兼容的库.当我正在处理服务器上托管的实时版本时,情况并非如此[它完全可以实现].

各种其他网站让我相信这可能是一个环境问题,因为我正在开发64位的Ubuntu发行版,我假设服务器版本运行在32位.然而,在将我的环境变量设置为:

CFLAGS+=" -m32"
CXXFLAGS+=" -m32"
Run Code Online (Sandbox Code Playgroud)

我仍然收到相同的编译错误:

/usr/bin/ld: skipping incompatible /dvlpmnt/libPI-Http.a when searching for -lPI-Http
Run Code Online (Sandbox Code Playgroud)

可以用教程吗?

== 编辑 ==

当我遵循乔纳森的建议时,这是我收到的输出:

http.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped
Run Code Online (Sandbox Code Playgroud)

显然,有问题的库毕竟是32位的?

psm*_*ars 35

该消息实际上并不是一个错误 - 它只是警告所讨论的文件不是正确的架构(例如32位与64位,错误的CPU架构).链接器将继续寻找正确类型的库.

当然,如果你也遇到了一个错误,你就会遇到can't find lPI-Http问题:-)

如果不了解构建系统和makefile的详细信息,很难说明确切的补救措施,但这里有几个黑暗的镜头:

  1. 只是为了检查:通常你会添加标志CFLAGS而不是 CTAGS- 你确定这是正确的吗?(你有什么可能是正确的 - 这将取决于你的构建系统!)
  2. 通常,标志也需要传递给链接器 - 因此您可能还需要修改 LDFLAGS

如果这没有用 - 你可以发布完整的错误输出,加上gcc foo.c -m32 -Dxxx正在执行的实际命令(例如等)吗?


Jon*_*ler 11

Normally, that is not an error per se; it is a warning that the first file it found that matches the -lPI-Http argument to the compiler/linker is not valid. The error occurs when no other library can be found with the right content.

So, you need to look to see whether /dvlpmnt/libPI-Http.a is a library of 32-bit object files or of 64-bit object files - it will likely be 64-bit if you are compiling with the -m32 option. Then you need to establish whether there is an alternative libPI-Http.a or libPI-Http.so file somewhere else that is 32-bit. If so, ensure that the directory that contains it is listed in a -L/some/where argument to the linker. If not, then you will need to obtain or build a 32-bit version of the library from somewhere.

To establish what is in that library, you may need to do:

mkdir junk
cd junk
ar x /dvlpmnt/libPI-Http.a
file *.o
cd ..
rm -fr junk
Run Code Online (Sandbox Code Playgroud)

' file'步骤告诉您归档中的目标文件类型.其余的只是确保你不会弄得一团糟,不容易清理.

  • 嗯,这很奇怪,这一步现在向我显示所有相关的库实际上都是 32 位的。哦哦 (2认同)