Spivoxity / obc-3

Oxford Oberon-2 compiler
38 stars 7 forks source link

Linking C primitives on the Mac #6

Closed Spivoxity closed 5 years ago

Spivoxity commented 5 years ago

Trying to follow your "How to add primitves to OBC" I get via obc -C when executing the think executable

$ ./think 
Fatal error: Can't find library ./prim.so: dlopen(./prim.so, 9): image not found

And when trying to compile the prim.so for the dynamic linking the __result is undefined

$ gcc -m32 -fPIC -shared -I /usr/local/lib/obc prim.c -o prim.so
Undefined symbols for architecture i386:
  "__result", referenced from:
      _Sleep_Usec in prim-fe3bdf.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

http://spivey.oriel.ox.ac.uk/corner/How_to_add_primitives_to_OBC

Spivoxity commented 5 years ago

The commands needed to build dynamic libraries are different on the Mac. It can be done, because it is done for the standard modules Math and MathL when the system is built, but you will need a different command line. I'll work it out when I have my Mac in front of me.

Spivoxity commented 5 years ago

The command you need is

gcc -m32 -fPIC -bundle -undefined dynamic_lookup -I /usr/local/lib/obc prim.c -o prim.so

I've updated the wiki page to note this. Method A as described on that page works unchanged, and Method B works with this one difference.

(I've no idea whether choosing -shared instead of -bundle makes any difference in this context.)