Error trying to build a fat universal binary with gcc on Ubuntu

此生再无相见时 提交于 2019-12-12 06:37:31

问题


I try to run a very simple code, but it reports error, can anyone give some suggestions? I am using Ubuntu14 and gcc4.9.

xin@ubuntu:~/pipes$ gcc -arch i386 -arch x86_64 channel.cpp
gcc: error: i386: No such file or directory
gcc: error: x86_64: No such file or directory
gcc: error: unrecognized command line option ‘-arch’
gcc: error: unrecognized command line option ‘-arch’

回答1:


Looks like you are trying to use the Apple OS/X (Darwin) GCC/CLang method of compiling code to a universal binary with 2 architectures.

It is different on Linux (including Ubuntu). Linux doesn't have universal binary support for multiple targets in a single executable. It is one architecture per build. Remove -arch i386 -arch x86_64 and replace it with -m32 if you are targeting a 32-bit binary, and -m64 if targeting a 64 bit binary.

32-bit:

gcc -m32 channel.cpp 

64-bit

gcc -m64 channel.cpp

Special Considerations

You may also have to install the Multilib versions of GCC (and G++ if you want to) so that you can properly build and run 32-bit applications on 64-bit Ubuntu using the appropriate C libraries. That can be done with this command line:

sudo apt-get install gcc-multilib g++-multilib

On other non-Ubuntu Debian based systems you'd need to use:

apt-get install gcc-multilib g++-multilib


来源:https://stackoverflow.com/questions/37281891/error-trying-to-build-a-fat-universal-binary-with-gcc-on-ubuntu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!