Sign in Join

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

Mailing lists / fpc-pascal / 2019-05

Problem linking external libs on Linux

7 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Anthony Walter

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.

Reply by email

Sven Barth
to Anthony Walter

Anthony Walter schrieb am So., 12. Mai 2019, 18:41:

Show quoted text 14 lines
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

Reply by email

Sven Barth
to Anthony Walter: Okay, so I need to install the dev versions of any package I want to link against. But…

Anthony Walter 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

Reply by email