Mac OS X + universal binary szivas

Fórumok

adott egy iBook G4, Mac OS X 10.4, XCode 2.5.

szeretnek universal binary lib-et es binarist kesziteni a kovetkezo file-okbol:$ cat main.,c
#include
#include "libtest.h"

int main(int argc, char **argv)
{
printf("main()\n");

libtest();

return 0;
}

$ cat libtest.h
#ifndef _LIBTEST_H_INCLUDED_
#define _LIBTEST_H_INCLUDED_

int libtest(void);

#endif /* _LIBTEST_H_INCLUDED_ */

$ cat libtest.c
#include
#include "libtest.h"

int libtest(void)
{
printf(" libtest()\n");

return 0;
}

$ gcc -fPIC -c -o obj/libtest.o libtest.c -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386
$ gcc -dynamiclib -o libtest.dylib -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386 ../obj/libtest.o
$ gcc -c -o obj/main.o main.c -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386
$ gcc -o bin/main -L/Users/shogy/aws/tmp/lib -ltest -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386 obj/main.o

a lib es a binaris letre is jon szepen, a problema:
$ otool -L bin/main
bin/main:
/var/tmp//cc4rO8rA.out (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 88.3.9)

azaz nem a libtest.dylib-et linkeli be, hanem - valoszinuleg - egy forditaskor keletkezo temp vackot.

az eloallitott object-ek, lib es a binaris epp azokat az arch-okat tartalmazza, amiket kertem:

$ file obj/*.o
obj/libtest.o: Mach-O fat file with 2 architectures
obj/libtest.o (for architecture ppc): Mach-O object ppc
obj/libtest.o (for architecture i386): Mach-O object i386
obj/main.o: Mach-O fat file with 2 architectures
obj/main.o (for architecture ppc): Mach-O object ppc
obj/main.o (for architecture i386): Mach-O object i386

$ file lib/libtest.dylib
lib/libtest.dylib: Mach-O fat file with 2 architectures
lib/libtest.dylib (for architecture ppc): Mach-O dynamically linked shared library ppc
lib/libtest.dylib (for architecture i386): Mach-O dynamically linked shared library i386

$ file bin/main
bin/main: Mach-O fat file with 2 architectures
bin/main (for architecture ppc): Mach-O executable ppc
bin/main (for architecture i386): Mach-O executable i386

amit kideritettem:
- a kulcs az, hogy a lib-be hany arch-ot pakolok. ha az csak ppc vagy csak i386 (es ertelemszeruen a binaris is), akkor a binaris jo lib-re fog hivatkozni:
$ otool -L bin/main
bin/main:
libtest.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 88.3.9)

- ha a lib multi-arch de a binaris single-arch, akkor is elcseszi a lib hivatkozast

probaltam google-al hasonlo problemat talalni, de nem talaltam.

mar a legujabb 2.5-os xcode-ot is letoltottem, de az eredmeny ugyanaz.

- van valakinem valami otlete, hogy mit cseszek el?

koszi,

shogy

Hozzászólások

aeon:asdasdasdasd pontscho$ gcc -arch i386 -arch ppc -dynamiclib -o libtest.dylib libtest.c
aeon:asdasdasdasd pontscho$ gcc -arch i386 -arch ppc -o main main.c libtest.dylib
aeon:asdasdasdasd pontscho$ otool -L main
main:
libtest.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.0.0)
aeon:asdasdasdasd pontscho$ ./main
main()
libtest()

-fPIC nem kell OSX-en.

---
pontscho / fresh!mindworkz