Problem linking external libs on Linux

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem linking external libs on Linux

Anthony Walter-3
I'm am not sure how long I've ignored this problem, but can someone explain to me the proper way to get FPC and Lazarus to allow linking of external shared object files without the need to create "friendly" symbolic link names FPC and Lazarus can see?

For example suppose I want to write some pascal code linking to an external functions like so:

const
  libsdl2 = 'libSDL2-2.0.so.0';
  
function SDL_Init(flags: Uint32): LongInt; cdecl; external libsdl2;
procedure SDL_Quit; cdecl; external libsdl2;

And when I try to compile the linking will likely failed because something is happening where the libsdl2 constant of 'libSDL2-2.0.so.0' is being converted to 'SDL2-2.0' at some point during the compilation or linking stage when working on Linux.

It is taking the constant, removing and 'lib' prefix, and anything after a '.so.'. So it's losing the '.0' at the end of my constant.

If I create symbolic link on my system like so, then the compilation and linking works:

sudo ln -s /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0 /usr/lib/libSDL2-2.0.so
 - or alternately -
sudo ln -s /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0 /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so

But I don't feel this is correct. I should be able to explicitly specify the standard name of the file name for the library which is 'libSDL2-2.0.so.0' and the compilation and linking stages should be able to use it with the '.0' at the end.

So my question is, what do I need to do either in Lazarus settings, fpc.cfg, or some other setting (possibly on my OS) to allow 'libSDL2-2.0.so.0' to work as a valid external library name without the need to create symbolic links?

By the way, I am using Ubuntu 16.4 64 bit if that is at all relevant.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Problem linking external libs on Linux

Free Pascal - General mailing list
Anthony Walter <[hidden email]> schrieb am So., 12. Mai 2019, 18:41:
For example suppose I want to write some pascal code linking to an external functions like so:

const
  libsdl2 = 'libSDL2-2.0.so.0';
  
function SDL_Init(flags: Uint32): LongInt; cdecl; external libsdl2;
procedure SDL_Quit; cdecl; external libsdl2;

And when I try to compile the linking will likely failed because something is happening where the libsdl2 constant of 'libSDL2-2.0.so.0' is being converted to 'SDL2-2.0' at some point during the compilation or linking stage when working on Linux.

This is indeed how it is supposed to work. You are supposed to link against the development library so that the linker can pick up the correct, real library. 

Regards, 
Sven 

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Problem linking external libs on Linux

Anthony Walter-3
Okay, so I need to install the dev versions of any package I want to link against. But when my program is distributed it will link at load time correctly to the non dev versions.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Problem linking external libs on Linux

fredvs
In reply to this post by Anthony Walter-3

https://bugs.freepascal.org/view.php?id=32367



-----
Many thanks ;-)
--
Sent from: http://free-pascal-general.1045716.n5.nabble.com/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: Problem linking external libs on Linux

Free Pascal - General mailing list
In reply to this post by Anthony Walter-3
Anthony Walter <[hidden email]> schrieb am So., 12. Mai 2019, 20:42:
Okay, so I need to install the dev versions of any package I want to link against. But when my program is distributed it will link at load time correctly to the non dev versions.

It links against the version the development version linked against. If the user has a different version installed (even if they have the development package installed) the application won't load of course. 

Regards, 
Sven 

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Problem linking external libs on Linux

Anthony Walter-3
In reply to this post by fredvs
Maybe close out that bug then?

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Problem linking external libs on Linux

fredvs
>> https://bugs.freepascal.org/view.php?id=32367

> Maybe close out that bug then?

Or fix it (Martin gave all the keys how to do, even Florian agree with it) ?




-----
Many thanks ;-)
--
Sent from: http://free-pascal-general.1045716.n5.nabble.com/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Many thanks ;-)