FFI & MacOS X

diego bart diegobt at hotmail.com
Thu Jun 10 05:28:29 UTC 2004


Hi, I am new to mac and I can't get FFI to work in MacOSX.
I am using the 3.6 carbon-classic vm. Im still a bit confused with
Mach-O. I was used to good'ole elf and dlls.

In order to test I wrote a small example and compiled it both .bundle
and .dylib following apple examples. I get the message "cannot find function
address".I can use them from C via the NS way (bundle) and linking to a dylib,
but cant get sq to find the symbols :(

THIS IS FOR THE DYLIB:
this would be answer.c:

int get_answer()
{
   return 42;
}

this would be deep.c:
#include <stdio.h>
int main()
{
        int answer;
        answer = get_answer();
        printf("the answer is %d\n", answer);
        return 0;
}

this would be the Makefile:
answer.o: answer.c
        cc -fno-common -c answer.c

libanswer.dylib: answer.o
        cc -dynamiclib -install_name libanswer.dylib \
        -o libanswer.dylib answer.o

deep.o: deep.c
        cc -fno-common -c deep.c

deep: deep.o libanswer.dylib
        $(LD) -o deep deep.o -L. -lanswer


FOR THE BUNDLE:
cc -flat_namespace -bundle -undefined supress \ -o libanswer.bundle
answer.o
I then use NSLookupSymbol() and NSAddressOfSymbol() functions (after
loading the file with other NS commands) in the deep.c file.


IN SQUEAK
I can't get this to work:

self prueba
	<cdecl: short 'get_answer' (void) module:'libanswer'>
	^self externalCallFailed

Question: which type of library does FFI use? .bundle or dylibs or both?
 Where does it look for it? putting it in the vm dir doesn't work, there
is no ldconfig (ahhhh!)./system/library/frameworks doesent work either (copying my lib into it I
mean)
The thing is I need to use ODBC with squeak in my mac (Diego Gomez
Deck's code I mean). In linux I simply symlinked libiodbc to the vm's directory. In OSX I got
libiodbc.dylib only.
Any help would be REALLY apreciated!
thx in advance!

/diego

 
 




More information about the Squeak-dev mailing list