Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apple's gcc, what's the difference between -arch i386 and -m32?

Tags:

macos

gcc

32-bit

According to Apple's gcc 4.2.1 doc:

-arch arch
Compile for the specified target architecture arch. The allowable values are 'i386', 'x86_64', 'ppc' and 'ppc64'. Multiple options work, and direct the compiler to produce “universal” binaries including object code for each architecture specified with -arch. This option only works if assembler and libraries are available for each architecture specified. (APPLE ONLY)

So what's the difference between these two calls:

gcc -arch i386 program.c

and

gcc -m32 program.c

Is it just that -arch is more powerful as it's more flexible and can produce universal binaries when specifiying multiple archs?

like image 918
Jean Regisser Avatar asked Nov 18 '09 08:11

Jean Regisser


1 Answers

I'm not sure but from reading the man page I get to similar conclusions as you do.

I guess the only real difference is that -arch can be used to create universal binaries.

As this works to create universal binaries

gcc -arch i386 -arch x86_64 foo.c

but you actually can't be sure what the semantics of the following should be (they probably are even invalid syntax). Especially the third should be invalid as the man pages says to generate for for 32- or 64-bit environments.

gcc -m32 -arch i386 -arch x86_64 foo.c
gcc -m64 -arch i386 -arch x86_64 foo.c
gcc -m32 -m64 -arch i386 -arch x86_64 foo.c
-m32
-m64
    Generate code for a 32-bit or 64-bit environment.  The 32-bit environment
    sets int, long and pointer to 32 bits and generates code that runs on any
    i386 system.  The 64-bit environment sets int to 32 bits and long and
    pointer to 64 bits and generates code for AMDs x86-64 architecture.
    For darwin only the -m64 option turns off the -fno-pic and 
    -mdynamic-no-pic options.

-arch //already included in question
like image 109
jitter Avatar answered Oct 06 '22 02:10

jitter