C++ 在编译时跳过不兼容的库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3119714/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Skipping Incompatible Libraries at compile
提问by kelly.dunn
When I try to compile a copy of my project on my local machine, I get an error stating that it 's skipping over incompatible libraries. This isn't the case when I'm messing around with the live version hosted on the server at work [it makes perfectly there].
当我尝试在我的本地机器上编译我的项目的副本时,我收到一条错误消息,指出它正在跳过不兼容的库。当我在工作中使用托管在服务器上的实时版本时,情况并非如此[它在那里完美无缺]。
Various other sites have lead me to believe that this might be an environment issue, as I'm developing on a 64-bit distro of Ubuntu and I assume the server version is running on 32-bit. Nevertheless, after setting my environment variables to:
其他各种网站让我相信这可能是环境问题,因为我正在 64 位 Ubuntu 发行版上进行开发,并且我假设服务器版本在 32 位上运行。尽管如此,在将我的环境变量设置为:
CFLAGS+=" -m32"
CXXFLAGS+=" -m32"
I still receive the same compile error of:
我仍然收到相同的编译错误:
/usr/bin/ld: skipping incompatible /dvlpmnt/libPI-Http.a when searching for -lPI-Http
Can haz tutorial?
可以haz教程吗?
==Edit==
==编辑==
This was the output I recieved when I followed Jonathan's advice:
这是我听从乔纳森的建议时收到的输出:
http.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped
Apparently, the library in question is 32-bit after all?
显然,有问题的库毕竟是 32 位的?
采纳答案by psmears
That message isn't actually an error - it's just a warning that the file in question isn't of the right architecture (e.g. 32-bit vs 64-bit, wrong CPU architecture). The linker will keep looking for a library of the right type.
该消息实际上并不是错误——它只是一个警告,指出相关文件的架构不正确(例如 32 位与 64 位,错误的 CPU 架构)。链接器将继续寻找正确类型的库。
Of course, if you're also getting an error along the lines of can't find lPI-Http
then you have a problem :-)
当然,如果您也遇到can't find lPI-Http
类似的错误,那么您就有问题了:-)
It's hard to suggest what the exact remedy will be without knowing the details of your build system and makefiles, but here are a couple of shots in the dark:
在不知道构建系统和 makefile 的详细信息的情况下,很难提出确切的补救措施,但这里有一些黑暗中的镜头:
- Just to check: usually you would add
flags to
CFLAGS
rather thanCTAGS
- are you sure this is correct? (What you have may be correct - this will depend on your build system!) - Often the flag needs to be passed to the linker too - so you may also need to modify
LDFLAGS
- 只是为了检查:通常你会添加标志
CFLAGS
而不是CTAGS
- 你确定这是正确的吗?(您所拥有的可能是正确的 - 这取决于您的构建系统!) - 通常该标志也需要传递给链接器 - 因此您可能还需要修改
LDFLAGS
If that doesn't help - can you post the full error output, plus the actual command (e.g. gcc foo.c -m32 -Dxxx
etc) that was being executed?
如果这没有帮助 - 您能否发布完整的错误输出,以及gcc foo.c -m32 -Dxxx
正在执行的实际命令(例如等)?
回答by Jonathan Leffler
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.
通常,这本身不是错误;这是一个警告,它发现与-lPI-Http
编译器/链接器的参数匹配的第一个文件无效。当找不到其他包含正确内容的库时,就会发生错误。
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.
因此,您需要查看/dvlpmnt/libPI-Http.a
是 32 位目标文件库还是 64 位目标文件库 - 如果您使用该-m32
选项进行编译,它可能是 64 位。然后,您需要确定其他地方是否有32 位的替代文件libPI-Http.a
或libPI-Http.so
文件。如果是这样,请确保包含它的目录列在-L/some/where
链接器的参数中。如果没有,那么您将需要从某个地方获取或构建该库的 32 位版本。
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
The 'file
' step tells you what type of object files are in the archive. The rest just makes sure you don't make a mess that can't be easily cleaned up.
' file
' 步骤告诉您存档中的目标文件类型。剩下的只是确保你不会弄得一团糟,不容易清理。