Error trying to build a fat universal binary with

2019-09-02 07:45发布

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条回答
做自己的国王
2楼-- · 2019-09-02 07:59

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
查看更多
登录 后发表回答