Search code examples
c++macosmakefileosx-snow-leopard

Is it possible to build 32-bit applications on OSX 10.6 that run on other OSX 10.6 systems?


When building C++ projects using make on OSX 10.6, I have determined that the preprocessor definition __LP64__ seems to be always automatically set by the compiler (i.e., it is not defined in any header file) (see Where is __LP64__ defined for default builds of C++ applications on OSX 10.6?). This leads to the question: Is it even possible to build a 32-bit application on OSX 10.6 that targets (and runs) on another OSX 10.6 system?

I have heard that OSX 10.6 is always a 64-bit OS - that it's not even possible to run OSX 10.6 as a 32-bit operating system. If this is the case, it would make sense that it is impossible to build a 32-bit application on OSX 10.6 that will run on another OSX 10.6 system.

I need to know this so I can know whether I'm building a 64-bit application or not (I have been attempting to build my current project as a 32-bit application, since the corresponding Windows version is also being built as 32-bit - but perhaps I need to enable all 64-bit flags and build the OSX 10.6 version of this application as a full-fledged 64-bit application).


Solution

  • Yes, it is perfectly possible to do that. One limited demonstration:

    $ tar -xf Packages/range-1.14.tgz
    $ cd range-1.14
    $ ls
    COPYING   Makefile  README    gpl-3.0.txt range.c   range.mk  stderr.c  stderr.h
    $ rmk CC='gcc -m32'
        gcc -m32 -g     -c stderr.c
        gcc -m32 -g     -c range.c
        gcc -m32 -o range -g     stderr.o range.o  
    $ file range
    range: Mach-O executable i386
    $ rmk -u CC='gcc -m64' 
        gcc -m64 -g     -c stderr.c
        gcc -m64 -g     -c range.c
        gcc -m64 -o range -g     stderr.o range.o  
    $ file range
    range: Mach-O 64-bit executable x86_64
    $ 
    

    rmk -u is equivalent to (GNU) make -B. This GCC is my home-built 4.6.0. You can do more with the Apple-provided versions of GCC - like cross-compiling and/or universal builds.