Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-10

using static linking of dylib in mac 10.5

4 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Guru Kathiresan

Hello,

I'm not able to do a static link of a dylib (with the latest lazarus + fpc build).

I'm using the following code:

function MyDyLibFunction: int; cdecl; external 'mylib.dylib';
begin
  MyDyLibFunction;
end;

If I use the LoadLibrary function to load the 'mylib.dylib' I'm getting a valid TLibHandle. Also the nm list MyDyLibFunction function (with _ prefix) in the library.

Can anyone give a pointer on how to make fpc statically link my shared library in mac osx?

Thanks,

Guru Kathiresan

Jonas Maebe
to Guru Kathiresan
Guru Kathiresan wrote 19 lines
I'm not able to do a static link of a dylib (with the latest lazarus + fpc build). I'm using the following code: function MyDyLibFunction: int; cdecl; external 'mylib.dylib'; begin MyDyLibFunction; end; If I use the LoadLibrary function to load the 'mylib.dylib' I'm getting a valid TLibHandle. Also the nm list MyDyLibFunction function (with _ prefix) in the library. Can anyone give a pointer on how to make fpc statically link my shared library in mac osx?

You cannot statically link a dynamic library. I guess you want to dynamically link it, but at compile time rather than manually at runtime using LoadLibrary(). To do so, add {$linkib mylib} to the source. This will also work on other platforms.

Jonas

Guru Kathiresan
to Jonas Maebe

Hi,
Thanks for the reply. That seems to work, but I think there is a bug in the FPC. When I do a {$linklib myfile.dylib} , it is not picking up the myfile.dylib, the compiler is looking for libmyfile.so . I had to rename the library from myfile.dylib to libmyfile.so .

-Guru Kathiresan

Show quoted text 40 lines
-----Original Message----- From: [mailto:fpc-pascal- On Behalf Of Jonas Maebe Sent: Monday, October 20, 2008 1:50 AM To: FPC-Pascal users discussions Subject: Re: [fpc-pascal] using static linking of dylib in mac 10.5 On 19 Oct 2008, at 20:54, Guru Kathiresan wrote: > I'm not able to do a static link of a dylib (with the latest lazarus > + fpc > build). > > I'm using the following code: > > function MyDyLibFunction: int; cdecl; external 'mylib.dylib'; > begin > MyDyLibFunction; > end; > > If I use the LoadLibrary function to load the 'mylib.dylib' I'm > getting a > valid TLibHandle. Also the nm list MyDyLibFunction function (with _ > prefix) > in the library. > > Can anyone give a pointer on how to make fpc statically link my shared > library in mac osx? You cannot statically link a dynamic library. I guess you want to dynamically link it, but at compile time rather than manually at runtime using LoadLibrary(). To do so, add {$linkib mylib} to the source. This will also work on other platforms. Jonas _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Jonas Maebe
to Guru Kathiresan
Guru Kathiresan wrote 6 lines
Thanks for the reply. That seems to work, but I think there is a bug in the FPC. When I do a {$linklib myfile.dylib} , it is not picking up the myfile.dylib, the compiler is looking for libmyfile.so . I had to rename the library from myfile.dylib to libmyfile.so .

Your library was simply named wrongly if it was called myfile.dylib. If you want the compiler and linker to find a dynamic library, its name must start with lib, so libmyfile.dylib (because to the linker you can only say -lmyfile, and then it automatically searches for libmyfile.dylib; maybe it also searches for libmyfile.so nowadays, I don't know).

Jonas