malloc compiled on Leopard fails on Tiger?

Discussion in 'Mac Programming' started by fredrikaustin, Jan 20, 2008.

  1. fredrikaustin macrumors newbie

    Joined:
    Jan 20, 2008
    #1
    Hello all,

    I'm wanting to be able to build c++ applications on a Leopard machine (it is PPC) but have the binaries able to execute on Tiger (intel or PPC). When my build machine was running Tiger, this was no problem.

    Now, even the simplest program involving malloc fails:

    void main() {
    // headers above and some printfs here removed for clarity
    void *p = malloc( 1024 );
    }

    gcc test.c -o test

    This simplest of programs of course runs without incident on Leopard. If I copy it to a machine running Tiger (PPC or intel), it crashes, with this in the crashreporter:

    <snip other stuff out here>

    Rosetta Version: 17.26
    Args: ./testsize
    Exception: EXC_BAD_ACCESS (0x0001)

    Thread 0: Crashed (0xb7fff9c0, 0xb80a564f)
    0x9012e090: /usr/lib/libSystem.B.dylib : __malloc_initialize + 0x34
    0x90002a5c: /usr/lib/libSystem.B.dylib : _malloc + 0x30
    0x90118d44: /usr/lib/libSystem.B.dylib : _localeconv_l + 0x64
    0x9000bb10: /usr/lib/libSystem.B.dylib : ___vfprintf$LDBL128 + 0x40
    0x9010466c: /usr/lib/libSystem.B.dylib : _vfprintf_l$LDBL128 + 0x7c
    0x90106a60: /usr/lib/libSystem.B.dylib : _printf$LDBL128 + 0x7c
    0x00001eb4: ./testsize : _main + 0x2c
    0x00001e34: ./testsize : start + 0x44
    0x00000000: ./testsize : + 0x0

    I have been googling like a madman for several hours and can't find the solution, which I'm sure is simple. I should point out that I'm relatively new to os x programming, but an experienced programmer... Any tips about gotchas building on Leopard but wanting to target Tiger would be appreciated.

    fa, austin tx
     
  2. toddburch macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas
    #2
    Methinks an experienced programmer would know better than
    Code:
    void main()
    
     
  3. fredrikaustin thread starter macrumors newbie

    Joined:
    Jan 20, 2008
    #3
    You have to be kidding...not only will that code compile, it has nothing to with my question. Anything helpful to add, or just upping the noise factor here?

    If I write it as "int main( void )" will that help, or do you need to see argv and argc also?
     
  4. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    I still don't get the whole linking process yet, but usually when you want to have a program run on a previous OS, you need to link using the SDK for that OS:

    Code:
    gcc test.c -o test -arch i386 -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk
     
  5. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #5
    The above program is just using the standard C library. There is no system specific code to require the platform SDK at all.

    Have you compiled it for both Intel and PPC because the error you posted says that the application was running under rosetta.
     
  6. sord macrumors 6502

    Joined:
    Jun 16, 2004
    #6
    He does need to compile with the 10.4u SDK. The 10.4u SDK vs the 10.5 SDK will have different libc versions, and really different lib* versions. Check out the contents of /Developer/SDKs/MacOSX10.4u.sdk/usr/lib/
     
  7. fredrikaustin thread starter macrumors newbie

    Joined:
    Jan 20, 2008
    #7
    Thanks for the informative replies. The post by kainjow got me on the right track, and I've finally landed at the relatively simple:

    gcc -mmacosx-version-min=10.4 test.c

    This version-min switch appears to take care of linking against the 10.4u sdk, as well as ensuring the proper crt is found and linked against (if you just do the -isysroot with the 10.4u, you'll get an ld: library not found crt1.10.5.o -- due to an error in the 10.5 toolchain - if you compile and link separately, the problem goes away, but I still couldn't run it on 10.4)

    So to summarize, the above version-min switch allowed me to build the app on Leopard, and run it on Tiger on both a PPC and Intel (on intel via Rosetta, and that's fine for me at the moment).

    Now to get all my gnu automake projects to use 10.4!

    -fa, austin tx
     

Share This Page