Sign in Join

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

Mailing lists / lazarus / 2012-09

Cannot load libpq.so

18 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

Leonardo M. Ramé

Hi, I've installed PostgreSql from sources on a Linux machine, it's installed on /usr/local/pgsql. It's libraries are in /usr/local/pgsql/lib, and I updated my /etc/ld.so.conf to look there, but still, when I run a simple testing app written with lazarus I'm getting this:

EInOutError : Can not load PostgreSQL client library "libpq.so". Check your installation

What can be happening?.

Regards,

Reply by email

zeljko
to Leonardo M. Ramé
Leonardo M. Ram? wrote 10 lines
Hi, I've installed PostgreSql from sources on a Linux machine, it's installed on /usr/local/pgsql. It's libraries are in /usr/local/pgsql/lib, and I updated my /etc/ld.so.conf to look there, but still, when I run a simple testing app written with lazarus I'm getting this: EInOutError : Can not load PostgreSQL client library "libpq.so". Check your installation What can be happening?.

Loader does not see /usr/local/pgsql/lib directory try
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH: /usr/local/pgsql/lib from terminal and then start your app ./myapplication

zeljko

Reply by email

Leonardo M. Ramé
to zeljko
zeljko wrote 20 lines
On Tuesday 25 of September 2012 19:56:52 Leonardo M. Ram? wrote: > Hi, I've installed PostgreSql from sources on a Linux machine, it's > installed on /usr/local/pgsql. It's libraries are in > /usr/local/pgsql/lib, and I updated my /etc/ld.so.conf to look there, > but still, when I run a simple testing app written with lazarus I'm > getting this: > > EInOutError : Can not load PostgreSQL client library "libpq.so". Check > your installation > > What can be happening?. Loader does not see /usr/local/pgsql/lib directory try export LD_LIBRARY_PATH=$LD_LIBRARY_PATH: /usr/local/pgsql/lib from terminal and then start your app ./myapplication zeljko

Thanks zeljko, but it still doesn't work. I even tried export LD_LIBRARY_PATH=/usr/local/pgsql/lib

Do you know a way to know where's the loader looking for libraries?, from command line.

Reply by email

Bernd
to Leonardo M. Ramé: Hi, I've installed PostgreSql from sources on a Linux machine, it's installed on…

2012/9/25 Leonardo M. Ram? :

Show quoted text 5 lines
Hi, I've installed PostgreSql from sources on a Linux machine, it's installed on /usr/local/pgsql. It's libraries are in /usr/local/pgsql/lib, and I updated my /etc/ld.so.conf to look there, but still, when I run a simple testing app written with lazarus I'm getting this:

did you run

sudo ldconfig

after changing /etc/ld.so.conf or installing new libs to update the cache?

Reply by email

Leonardo M. Ramé
to Bernd
Bernd wrote 13 lines
2012/9/25 Leonardo M. Ram? : > Hi, I've installed PostgreSql from sources on a Linux machine, it's > installed on /usr/local/pgsql. It's libraries are in > /usr/local/pgsql/lib, and I updated my /etc/ld.so.conf to look there, > but still, when I run a simple testing app written with lazarus I'm > getting this: did you run sudo ldconfig after changing /etc/ld.so.conf or installing new libs to update the cache?

Yes. One thing that raised my attention was I had to run it as root, then logged-out from my account, logged-in again but the error is still there.

One more thing, I've tried "ldd myapp" and it doesn't looks for libpq.so, I seems to be dynamically loading the shared object.

Reply by email

Leonardo M. Ramé
to Bernd
Bernd wrote 10 lines
2012/9/25 Leonardo M. Ram? : > Do you know a way to know where's the loader looking for libraries?, > from command line. ldconfig --print-cache Your library should appear there if installed correctly --

Here's the result of ldconfig:

/sbin/ldconfig --print-cache|grep libpq
libpqwalreceiver.so (libc6) => /usr/local/pgsql/lib/libpqwalreceiver.so libpq.so.5 (libc6) => /usr/local/pgsql/lib/libpq.so.5 libpq.so (libc6) => /usr/local/pgsql/lib/libpq.so

It seems to be installed correctly.

Reply by email

Bernd
to Bernd: 2012/9/25 Leonardo M. Ram? : ldconfig --print-cache Your library should appear there if…

2012/9/25 Bernd :

Show quoted text 8 lines
2012/9/25 Leonardo M. Ram? : > Do you know a way to know where's the loader looking for libraries?, > from command line. ldconfig --print-cache Your library should appear there if installed correctly

It also might be installed as something like libpq.so.1 while your program is trying to load libpq.so. Then you might need to add a symlink. This is normally not a problem when linking at link time because ld would resolve the symlink (which only exists when the headers are installed) and insert the real name (the so called soname) into the binary but this does not work when you are loading dynamically at runtime.

Reply by email

Leonardo M. Ramé
to Bernd: 2012/9/25 Bernd : It also might be installed as something like libpq.so.1 while your…
Bernd wrote 19 lines
2012/9/25 Bernd : > 2012/9/25 Leonardo M. Ram? : > >> Do you know a way to know where's the loader looking for libraries?, >> from command line. > > ldconfig --print-cache > > Your library should appear there if installed correctly It also might be installed as something like libpq.so.1 while your program is trying to load libpq.so. Then you might need to add a symlink. This is normally not a problem when linking at link time because ld would resolve the symlink (which only exists when the headers are installed) and insert the real name (the so called soname) into the binary but this does not work when you are loading dynamically at runtime. --

Yes, I understand this, the problem is that I don't have control on how my program loads the library, I just placed a PostgreSql Database connector on a Data Module using Lazarus, so, the database connector must know where's libpq.so.

Reply by email

Mark Morgan Lloyd
to zeljko: Loader does not see /usr/local/pgsql/lib directory try export…
zeljko wrote 16 lines
On Tuesday 25 of September 2012 19:56:52 Leonardo M. Ram? wrote: > Hi, I've installed PostgreSql from sources on a Linux machine, it's > installed on /usr/local/pgsql. It's libraries are in > /usr/local/pgsql/lib, and I updated my /etc/ld.so.conf to look there, > but still, when I run a simple testing app written with lazarus I'm > getting this: > > EInOutError : Can not load PostgreSQL client library "libpq.so". Check > your installation > > What can be happening?. Loader does not see /usr/local/pgsql/lib directory try export LD_LIBRARY_PATH=$LD_LIBRARY_PATH: /usr/local/pgsql/lib from terminal and then start your app ./myapplication

Do you actually /have/ a libpq.so? I've usually had to set up a symlink to get the names right.

As I understand it, there's an optional parameter on the library initialisation call to specify the exact library name, and there was recent discussion about how best to expose this to programmers via the LCL.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Leonardo M. Ramé
to Bernd: 2012/9/25 Leonardo M. Ram? : maybe libpq.so itself has some dependency problems and will…
Bernd wrote 10 lines
2012/9/25 Leonardo M. Ram? : > libpq.so (libc6) => /usr/local/pgsql/lib/libpq.so > > It seems to be installed correctly. maybe libpq.so itself has some dependency problems and will refuse to load (but I am not sure how the error message would look like in this case, so this is only an unfounded guess. try ldd on the library itself)

I thought so, but it doesn't have dependencies.

Reply by email

Leonardo M. Ramé
to Mark Morgan Lloyd: Do you actually /have/ a libpq.so? I've usually had to set up a symlink to get the names…
Mark Morgan Lloyd wrote 31 lines
zeljko wrote: >On Tuesday 25 of September 2012 19:56:52 Leonardo M. Ram? wrote: >>Hi, I've installed PostgreSql from sources on a Linux machine, it's >>installed on /usr/local/pgsql. It's libraries are in >>/usr/local/pgsql/lib, and I updated my /etc/ld.so.conf to look there, >>but still, when I run a simple testing app written with lazarus I'm >>getting this: >> >>EInOutError : Can not load PostgreSQL client library "libpq.so". Check >>your installation >> >>What can be happening?. > >Loader does not see /usr/local/pgsql/lib directory >try export LD_LIBRARY_PATH=$LD_LIBRARY_PATH: /usr/local/pgsql/lib >from terminal and then start your app ./myapplication Do you actually /have/ a libpq.so? I've usually had to set up a symlink to get the names right. As I understand it, there's an optional parameter on the library initialisation call to specify the exact library name, and there was recent discussion about how best to expose this to programmers via the LCL. -- Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

libpq.so is a symlink to libpq.so.5.4, yes, I have both.

Reply by email

Bernd
to Mark Morgan Lloyd: Do you actually /have/ a libpq.so? I've usually had to set up a symlink to get the names…

2012/9/25 Mark Morgan Lloyd :

As I understand it, there's an optional parameter on the library initialisation call to specify the exact library name, and there was recent discussion about how best to expose this to programmers via the LCL.

Libraries should simply be loaded by their soname and not by the name of the symlink (which exists only when the dev package of the lib is installed), the symlink only exists as a hint for ld at link time so it can follow it and find the real soname to link the binary against. The soname is the canonical name of the library and is guaranteed to exist.

Reply by email

zeljko
to Leonardo M. Ramé: Here's the result of ldconfig: /sbin/ldconfig --print-cache|grep libpq…
Leonardo M. Ram? wrote 19 lines
On 2012-09-25 20:35:43 +0200, Bernd wrote: > 2012/9/25 Leonardo M. Ram? : > > Do you know a way to know where's the loader looking for libraries?, > > from command line. > > ldconfig --print-cache > > Your library should appear there if installed correctly > > -- Here's the result of ldconfig: /sbin/ldconfig --print-cache|grep libpq libpqwalreceiver.so (libc6) => /usr/local/pgsql/lib/libpqwalreceiver.so libpq.so.5 (libc6) => /usr/local/pgsql/lib/libpq.so.5 libpq.so (libc6) => /usr/local/pgsql/lib/libpq.so It seems to be installed correctly.

If you compiled it by yourself then something goes wrong probably. Maybe you've compiled 64bit lib and tried to load it with 32bit app ? You can easy test that. Create new application, include dynlibs and try to load that library in some event (eg. ButtonOnClick). According to your posts ld.conf contains valid entries and libpq.so is in the path, so something else is wrong .

zeljko

Reply by email

Leonardo M. Ramé
to zeljko
zeljko wrote 30 lines
On Tuesday 25 of September 2012 20:42:18 Leonardo M. Ram? wrote: > On 2012-09-25 20:35:43 +0200, Bernd wrote: > > 2012/9/25 Leonardo M. Ram? : > > > Do you know a way to know where's the loader looking for libraries?, > > > from command line. > > > > ldconfig --print-cache > > > > Your library should appear there if installed correctly > > > > -- > > Here's the result of ldconfig: > > /sbin/ldconfig --print-cache|grep libpq > libpqwalreceiver.so (libc6) => /usr/local/pgsql/lib/libpqwalreceiver.so > libpq.so.5 (libc6) => /usr/local/pgsql/lib/libpq.so.5 > libpq.so (libc6) => /usr/local/pgsql/lib/libpq.so > > It seems to be installed correctly. If you compiled it by yourself then something goes wrong probably. Maybe you've compiled 64bit lib and tried to load it with 32bit app ? You can easy test that. Create new application, include dynlibs and try to load that library in some event (eg. ButtonOnClick). According to your posts ld.conf contains valid entries and libpq.so is in the path, so something else is wrong . zeljko

I've made this simple program to test what's happening while loading libpq.so.

Important: I must point out that I'm running FPC 2.7.1 on a Linux PowerPC 64 bits machine. And it works ok on an x86_64 Ubuntu PC.

The result I'm getting when calling "RaiseLastOSError" is this:

An unhandled exception occurred at $000000001001582C: EOSError: An operating system call failed.
$000000001001582C

Here's the program:

program test;
{$mode objfpc}{$H+}

uses
sysutils,

  dynlibs;
const
  cLibrary = '/usr/local/pgsql/lib/libpq.so';
var
  lHandle: TLibHandle;
begin
   if not FileExists(cLibrary) then
   begin
     writeln('Library ' + cLibrary + ' does not exists.');
     halt;
   end;
   lHandle := LoadLibrary(cLibrary);
   if lHandle = 0 then
   begin
     writeln('Library not loaded');
     RaiseLastOSError;
   end;
end.

Reply by email

Leonardo M. Ramé
to Leonardo M. Ramé
Leonardo M. Ram? wrote 76 lines
On 2012-09-26 07:42:29 +0200, zeljko wrote: > On Tuesday 25 of September 2012 20:42:18 Leonardo M. Ram? wrote: > > On 2012-09-25 20:35:43 +0200, Bernd wrote: > > > 2012/9/25 Leonardo M. Ram? : > > > > Do you know a way to know where's the loader looking for libraries?, > > > > from command line. > > > > > > ldconfig --print-cache > > > > > > Your library should appear there if installed correctly > > > > > > -- > > > > Here's the result of ldconfig: > > > > /sbin/ldconfig --print-cache|grep libpq > > libpqwalreceiver.so (libc6) => /usr/local/pgsql/lib/libpqwalreceiver.so > > libpq.so.5 (libc6) => /usr/local/pgsql/lib/libpq.so.5 > > libpq.so (libc6) => /usr/local/pgsql/lib/libpq.so > > > > It seems to be installed correctly. > > If you compiled it by yourself then something goes wrong probably. Maybe > you've compiled 64bit lib and tried to load it with 32bit app ? > You can easy test that. Create new application, include dynlibs and try to > load that library in some event (eg. ButtonOnClick). According to your posts > ld.conf contains valid entries and libpq.so is in the path, so something else > is wrong . > > zeljko > I've made this simple program to test what's happening while loading libpq.so. Important: I must point out that I'm running FPC 2.7.1 on a Linux PowerPC 64 bits machine. And it works ok on an x86_64 Ubuntu PC. The result I'm getting when calling "RaiseLastOSError" is this: An unhandled exception occurred at $000000001001582C: EOSError: An operating system call failed. $000000001001582C Here's the program: program test; {$mode objfpc}{$H+} uses sysutils, dynlibs; const cLibrary = '/usr/local/pgsql/lib/libpq.so'; var lHandle: TLibHandle; begin if not FileExists(cLibrary) then begin writeln('Library ' + cLibrary + ' does not exists.'); halt; end; lHandle := LoadLibrary(cLibrary); if lHandle = 0 then begin writeln('Library not loaded'); RaiseLastOSError; end; end.

I've created a bug report here:
http://bugs.freepascal.org/view.php?id=22987

It's related to FPC and not Lazarus.

Regards,

Reply by email