OpenLibrary() dose not work

Just starting out? Need help? Post your questions and find answers here.
Wolfram
Enthusiast
Enthusiast
Posts: 604
Joined: Thu May 30, 2013 4:39 pm

OpenLibrary() dose not work

Post 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() ?
macOS Catalina 10.15.7
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: OpenLibrary() dose not work

Post 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.
Wolfram
Enthusiast
Enthusiast
Posts: 604
Joined: Thu May 30, 2013 4:39 pm

Re: OpenLibrary() dose not work

Post by Wolfram »

How can I use a .o Library?
macOS Catalina 10.15.7
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: OpenLibrary() dose not work

Post by Danilo »

Probably using Import/ImportC.
tejon
User
User
Posts: 29
Joined: Sat May 17, 2003 12:38 am

Re: OpenLibrary() dose not work

Post 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.
Wolfram
Enthusiast
Enthusiast
Posts: 604
Joined: Thu May 30, 2013 4:39 pm

Re: OpenLibrary() dose not work

Post 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?
macOS Catalina 10.15.7
tejon
User
User
Posts: 29
Joined: Sat May 17, 2003 12:38 am

Re: OpenLibrary() dose not work

Post by tejon »

if a.o is a 32-bit object then try the following
gcc -m32 -shared -o a.dylib a.o
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: OpenLibrary() dose not work

Post 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.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: OpenLibrary() dose not work

Post 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.
Windows (x64)
Raspberry Pi OS (Arm64)
Post Reply