In case anyone else runs into this, below is how to build a library  
for MacOSX that can be loaded by both 32-bit and 64-bit versions of  
Factor.

To support both 64bit and 32bit architectures, add the flags "-arch  
i386 -arch x86_64". This will create a library that supports both  
architectures. For example:

cc -arch i386 -arch x86_64 -fno-common -c tester.c
cc -arch i386 -arch x86_64 -dynamiclib -install_name tester.dylib -o  
tester.dylib tester.o

Thanks,

Glenn

V. Glenn Tarcea
[email protected]

On Jul 15, 2009, at 6:40 AM, Glenn Tarcea wrote:

> Thanks Bruno, that is the problem. It turns out that the library  
> also needs to be built 64 bit. I verified this by building a small  
> utility as 64-bit and tried linking it against a 32-bit library.  
> MacOSX doesn't like this. I'll have to rebuild BerkeleyDB for 64 bit.
>
> The dlopen man page implies that 64bit and 32bit libraries can be  
> loaded on a 64bit system. I wonder if there is a universal linker  
> option that would allow this...
>
> Thanks for the pointer. I'll have to do a bit more exploring.
>
> Thanks,
>
> Glenn
>
> V. Glenn Tarcea
> [email protected]
>
> On Jul 14, 2009, at 10:28 PM, Bruno Deferrari wrote:
>
>> I had the same problem before (on OSX too). The cause was that I was
>> trying to load 32bits libraries running 64bits factor. When I
>> recompiled factor for 32bits the libraries loaded fine.
>>
>> On Tue, Jul 14, 2009 at 10:37 PM, Glenn Tarcea<[email protected]>  
>> wrote:
>>> Hi,
>>>
>>> I had some working alien code that I haven't touched in a while. I'm
>>> back at it getting it to compile and trying to test it.  
>>> Unfortunately
>>> I can't get Factor to recognize my DLL libraries. Is there something
>>> that has changed with the way the libraries should be built/ 
>>> recognized
>>> on MacOSX?
>>>
>>> For example, the following library used to load:
>>>
>>> /usr/local/BerkeleyDB.4.5/lib/libdb-4.5.dylib
>>>
>>> If I run "file" on it I get:
>>> libdb-4.5.dylib: Mach-O dynamically linked shared library i386
>>>
>>> However, if I do the following:
>>>
>>> "/usr/local/BerkeleyDB.4.5/lib/libdb-4.5.dylib" dlopen dll-valid?
>>> I always get false.
>>>
>>> I tried loading a very simple library that I created myself to test
>>> things. The c code is:
>>>
>>> int myfunc()
>>> {
>>>    return 53 ;
>>> }
>>>
>>>
>>> I build it as:
>>> cc -fno-common -c tester.c
>>> cc -dynamiclib -install_name tester.dylib -o tester.dylib tester.o
>>>
>>> My FFI Interface is:
>>> ========
>>> USING: alien alien.libraries alien.syntax combinators kernel  
>>> system ;
>>>
>>> IN: berkeleydb.ffitest
>>>
>>> << "tester" {
>>>    { [ os winnt? ] [ "libdb.dll" "stdcall" ] }
>>>    { [ os macosx? ] [ "/usr/local/ffitest/tester.dylib" "cdecl" add-
>>> library ] }
>>>    { [ os unix? ] [ "libbdb.so" "cdecl" ] }
>>>    [ "OS Not supported" throw ]
>>> } cond >>
>>>
>>> LIBRARY: tester
>>>
>>> FUNCTION: int myfunc ( ) ;
>>> ============
>>>
>>> Factor won't recognize this library either (with dlopen and dll-
>>> valid?). Nor will it execute the myfunc word, instead it always
>>> complains that a symbol or library is missing (which makes sense  
>>> since
>>> it doesn't seem to recognize tester.dylib as a valid library).
>>>
>>> If I just link an C program with the library, it will run (program  
>>> is
>>> not statically linked).
>>>
>>> Thanks,
>>>
>>> Glenn
>>>
>>> V. Glenn Tarcea
>>> [email protected]
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Enter the BlackBerry Developer Challenge
>>> This is your chance to win up to $100,000 in prizes! For a limited  
>>> time,
>>> vendors submitting new applications to BlackBerry App World(TM)  
>>> will have
>>> the opportunity to enter the BlackBerry Developer Challenge. See  
>>> full prize
>>> details at: http://p.sf.net/sfu/Challenge
>>> _______________________________________________
>>> Factor-talk mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/factor-talk
>>>
>>
>> ------------------------------------------------------------------------------
>> Enter the BlackBerry Developer Challenge
>> This is your chance to win up to $100,000 in prizes! For a limited  
>> time,
>> vendors submitting new applications to BlackBerry App World(TM)  
>> will have
>> the opportunity to enter the BlackBerry Developer Challenge. See  
>> full prize
>> details at: http://p.sf.net/sfu/Challenge
>> _______________________________________________
>> Factor-talk mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/factor-talk
>>
>>
>


------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to