Page 1 of 1

OpenLibrary() dose not work

Posted: Wed Dec 30, 2015 6:18 pm
by Wolfram
On OSX are different types of libraries.
If I look inside /usr/lib/ there are some withe extension .o, some with .a, .so and some .dylib.

Is it normal that I can only use .dylib with OpenLibrary() ?

Re: OpenLibrary() dose not work

Posted: Wed Dec 30, 2015 6:27 pm
by Danilo
.dylib = dynamic library
.dll = dynamic link library

.a, .o, .so, .obj, .lib are objects/libraries for use with the linker, not dynamically at runtime.

Re: OpenLibrary() dose not work

Posted: Wed Dec 30, 2015 6:42 pm
by Wolfram
How can I use a .o Library?

Re: OpenLibrary() dose not work

Posted: Wed Dec 30, 2015 6:47 pm
by Danilo
Probably using Import/ImportC.

Re: OpenLibrary() dose not work

Posted: Wed Dec 30, 2015 6:55 pm
by tejon
if that don't work you could try and make a dylib, copy the a.o file to some temp folder and then launch the terminal, cd to to the temp folder and issue the following command
gcc -shared -o a.dylib a.o
the reason for using gcc instead of ar is that gcc will try to find dependencies if any.

Re: OpenLibrary() dose not work

Posted: Wed Dec 30, 2015 9:41 pm
by Wolfram
tejon wrote:if that don't work you could try and make a dylib, copy the a.o file to some temp folder and then launch the terminal, cd to to the temp folder and issue the following command
gcc -shared -o a.dylib a.o
the reason for using gcc instead of ar is that gcc will try to find dependencies if any.
I get an error:
file was built for i386 which is not the architecture being linked (x86_64).

Can you tell me how to fix that?

Re: OpenLibrary() dose not work

Posted: Wed Dec 30, 2015 10:19 pm
by tejon
if a.o is a 32-bit object then try the following
gcc -m32 -shared -o a.dylib a.o

Re: OpenLibrary() dose not work

Posted: Thu Dec 31, 2015 7:08 am
by Danilo
Wolfram wrote:I get an error:
file was built for i386 which is not the architecture being linked (x86_64).
Sounds like you are trying to use a x86 lib with PB x64. Use PB x86 with x86 libs,
and PB x64 with 64-bit libs.

Re: OpenLibrary() dose not work

Posted: Thu Dec 31, 2015 7:29 am
by wilbert
Danilo wrote:.a, .o, .so, .obj, .lib are objects/libraries for use with the linker, not dynamically at runtime.
As far as I understand both .dylib and .so can be loaded at runtime.
If you need a little more control compared to OpenLibrary, you can use dlopen, dlsym, dlclose and dlerror .
.a and .o can indeed be used with ImportC.