* * *

Author Topic: libpq.dylib unreachable ?  (Read 638 times)

ThierryJ

  • New member
  • *
  • Posts: 10
libpq.dylib unreachable ?
« on: May 21, 2018, 08:34:58 pm »
Hello There,

I am trying to connect to my PostgreSQL server from Lazarus using a TPQConnection standard component. When I try to connect, I am receiving this alert :

Can not load PostgreSQL client library "libpq.dylib". Check your installation.

I have checked, the library is present in /usr/lib. It is in fact a link pointing to libpq.5.6.dylib.

I assume that the parameters are correct, since when I look to the files opened by the Lazarus process when running I find this : /usr/lib/dyld. Lazarus knows where to find its libraries.

So, what is happening ? I have exactly the same problem on another machine, running the same versions of osx, Lazarus and fpc.

My configuration :

MacOS High Sierra 10.13.4
Lazarus 1.8.2
FPC 3.0.4
gdb 8.0.1 (signed, working from Lazarus)

Any comment or suggestion will be welcome, I am fighting since more than one day with this and I am becoming tired...

Thanks in advance,

Thierry


Phil

  • Hero Member
  • *****
  • Posts: 2652
Re: libpq.dylib unreachable ?
« Reply #1 on: May 21, 2018, 08:52:07 pm »
Can not load PostgreSQL client library "libpq.dylib". Check your installation.

I assume you've looked at the code in postgres3dyn.pp and seen that it's calling LoadLibrary to load libpq.dylib.

But it doesn't include absolute path to library. FPC docs have always suggested including an absolute path:

https://www.freepascal.org/docs-html/rtl/dynlibs/loadlibrary.html

Easy for you to check if that's the problem. If so, file a bug report.

ThierryJ

  • New member
  • *
  • Posts: 10
Re: libpq.dylib unreachable ?
« Reply #2 on: May 22, 2018, 10:23:10 am »
Hello Phil,

Thank you for your answer. I have tried to locate postgres3dyn.pp :

Code: [Select]
iMac27:lazarus me$ pwd
/Developer/lazarus
iMac27:lazarus me$ find . -name "*.pp" -print | grep postgres
iMac27:lazarus me$

So, this file is not on my system (??) Anyway I found this forum entry : http://forum.lazarus-ide.org/index.php?topic=15782.0. Same problem, none of the mentioned files or units are present on my system... The post is old, 2012.

I have built the SQLdb package, with success, but nothing has changed after.

Do you think that I will have to build Lazarus from sources instead of just installing it from the official package ?

Do you have any more information ? I am lost...

Thanks in advance,

Thierry


marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6243
Re: libpq.dylib unreachable ?
« Reply #3 on: May 22, 2018, 11:28:31 am »
Base Database classes are non-visual, so part of FPC, not Lazarus.

ThierryJ

  • New member
  • *
  • Posts: 10
Re: libpq.dylib unreachable ?
« Reply #4 on: May 22, 2018, 07:29:13 pm »
OK, found. Looking to the code, I see that there is no assumption about the path where the library should be on Darwin. Does it mean that I have to modify this code to fix the path to /usr/lib/libpq.dylib ? It is useless to build a rather complicated way to determine the suffix of the library and still ignoring its location...

It is so strange to have to proceed this way on systems able to establish logical links to physical files... I am completely new to fpc and Lazarus, so it is difficult to me to evaluate the effort required to use simply the configuration file settings for reaching this library. But obviously some other modules do this because I can see that /usr/lib/dyld is in use when Lazarus/fpc are running.

I have tried to copy / rename libpq.dylib to /Developer/lazarus/ directory, beside the lazarus binary, but I still get the same message.

If you can give me a clue on where to find a good doc about building fpc and/or its modules, I would be very grateful...

Thanks in advance,

Thierry
 

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6243
Re: libpq.dylib unreachable ?
« Reply #5 on: May 22, 2018, 07:35:22 pm »
OK, found. Looking to the code, I see that there is no assumption about the path where the library should be on Darwin. Does it mean that I have to modify this code to fix the path to /usr/lib/libpq.dylib ?

Afaik you can define an unit that calls in its initialization to the initialize* procedure in dyn<database>* to manual specify the library name. If you put that unit first in the project, it should work.


ThierryJ

  • New member
  • *
  • Posts: 10
Re: libpq.dylib unreachable ?
« Reply #6 on: May 25, 2018, 06:16:36 pm »
Hello Marco,

Thanks for your answer. I have tried your suggestion. In fact, there is no more chance to get to the library by proceding manually than there are by letting the system load this library automatically. So the result is exactly the same, apart of that the error message appears when I compile the Initialization Unit (Unit2 in my proto).
In parallel to these tests I have installed Lazarus + fpc in Ubuntu on a VM and tried to build the same exemple as on OSX. It worked perfectly as soon as I had installed Postgres, wich brings the library (with another extension). So, in general the loading mechanism seems to work, but there is for sure a problem on MacOS : today I have cleaned my original installation and re-installed the new packages with Lazarus 1.8.4, the problem is still present.
It is highly frustrating, because if I do something with Lazarus/fpc it will have to run on a Mac along with Postgres, not on Ubuntu.

But, a question : Could it be a mismatch in the bitsize of the library, since Lazarus is built in 32 bits on the Mac and Postgres is 64 bits ?

If yes, do you have any idea on how to build this library ? From the Postgres sources ?

Hoping to read from you,

Thierry

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6243
Re: libpq.dylib unreachable ?
« Reply #7 on: May 25, 2018, 07:38:27 pm »
FPC 32/64-bit must match the dylib  32/64-bit.

The connection between the dylib and the server is via tcp/IP instead of linking so there it doesn't have to match.

I assume the Mac builds of OS X (or its ports system) have the appropriate libraries.

p.s.
I see a

Function InitialisePostgres3(Const libpath : ansistring) : integer;

function in postgres3dyn, as I expected

ThierryJ

  • New member
  • *
  • Posts: 10
Re: libpq.dylib unreachable ?
« Reply #8 on: May 27, 2018, 01:30:16 pm »
Hello,

I have tried to initialize the library using this function, but no result, always the same message.

I have made another attempt with a MySQL(57) connector, to speak to a MariaDB database on the localhost. And I get the same result :

"Can not load default MySQL library ("libmysqlclient.dylib.20" or "libmysqlclient.dylib". Check your installation"

After a check, everything looks in place :

iMac27:~ thierry$ dir /usr/local/lib/libmy*
lrwxr-xr-x  1 thierry  admin  45 26 mai 14:33 /usr/local/lib/libmysqlclient.a -> ../Cellar/mariadb/10.3.7/lib/libmysqlclient.a
lrwxr-xr-x  1 thierry  admin  49 26 mai 14:33 /usr/local/lib/libmysqlclient.dylib -> ../Cellar/mariadb/10.3.7/lib/libmysqlclient.dylib
lrwxr-xr-x  1 thierry  admin  47 26 mai 14:33 /usr/local/lib/libmysqlclient_r.a -> ../Cellar/mariadb/10.3.7/lib/libmysqlclient_r.a
lrwxr-xr-x  1 thierry  admin  51 26 mai 14:33 /usr/local/lib/libmysqlclient_r.dylib -> ../Cellar/mariadb/10.3.7/lib/libmysqlclient_r.dylib
lrwxr-xr-x  1 thierry  admin  47 26 mai 14:33 /usr/local/lib/libmysqlservices.a -> ../Cellar/mariadb/10.3.7/lib/libmysqlservices.a
iMac27:~ thierry$

Another question : Am I the only guy on this planet trying to use the SQLDb components to access standard databases ? If not, how did the others proceed, where am I wrong ?

I am used to Delphi since its beginnings, maybe I don't know some special way to use components in Lazarus ? In Delphi, you take the one you need, you put it on the form, give value to the needed parameters and it works right out of the box. Maybe its not the right way with Lazarus ?

Anyway, the problem seems exclusive to MacOS, under Ubuntu the things looks OK at this step. But I need MacOS...


marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6243
Re: libpq.dylib unreachable ?
« Reply #9 on: May 27, 2018, 05:10:23 pm »
  question : Am I the only guy on this planet trying to use the SQLDb components to access standard databases ?

No, I use sqldb myself with postgres and sqlite.  Mostly windows clients and linux servers. An older app, but more significant app uses Zeos and can still be compiled with delphi.
 
Quote
I am used to Delphi since its beginnings, maybe I don't know some special way to use components in Lazarus ? In Delphi, you take the one you need, you put it on the form, give value to the needed parameters and it works right out of the box. Maybe its not the right way with Lazarus ?

I never used Delphi on mac, so don't know how well it works. But I can remember that I had problems installing zeos into windows. I had to add the built .bpl path (which Delphi itself had compiled to) to the windows path for some reason.
 

Phil

  • Hero Member
  • *****
  • Posts: 2652
Re: libpq.dylib unreachable ?
« Reply #10 on: May 27, 2018, 05:19:06 pm »
I have tried to initialize the library using this function, but no result, always the same message.

Have you resolved the bitness issue? Postgres is 64-bit only on Mac. That means you can't use the Carbon widgetset (default) for your apps that load the libpq.dylib library since Carbon is 32-bit only.

You can compile Lazarus and the LCL for 64-bit with the Cocoa widgetset, but you'll have to use the trunk source for Lazarus. Here are some notes:

https://macpgmr.github.io/MacXPlatform/UsingCocoaFromTrunk.html

Start simple. For example, make sure your app can actually load a given library, whether libpq.dylib or some other. You can do this in just a few lines of code:

Code: Pascal  [Select]
  1. program testpqlib;
  2.  
  3. {$linklib pq}
  4.  
  5. begin
  6. end.
  7.  

Compile that with ppcx64 and it links and runs fine. But compile it with ppc386 and you get a linker error that tells you everything you need to know.

Also, it doesn't look like Postgres even has a 32-bit version of the client library for Mac:

https://www.postgresql.org/download/macosx/

You can determine the architectures that a library supports using the file command. Eg,

file /usr/lib/libpq.dylib

This shows that Postgres is only 64-bit. But this:

file /usr/lib/libsqlite3.dylib

shows multiple architectures.


ThierryJ

  • New member
  • *
  • Posts: 10
Re: libpq.dylib unreachable ?
« Reply #11 on: May 27, 2018, 06:01:56 pm »
Phil,

Thank you for your directions. I reached the point where the bitness is the only logical explanation to these problems.
I will follow your indications and try to build a true 64 bits Lazarus.
I have tried to get a 32 bits clients from Postgres, no way. And anyway, carbon is about to die, it is time to move from it. But I was not expecting to have to do it by myself. I am an old man now, and all this stuff is far away in my background !
I will come back with news as soon as I will have some.

ThierryJ

  • New member
  • *
  • Posts: 10
Re: libpq.dylib unreachable ?
« Reply #12 on: May 27, 2018, 08:37:55 pm »
Phil,

Thank you once more. I have been able to build Lazarus with Cocoa, it seems to work, except for the debugger.

More important, I have learned the "file" command ! And I have been able to compile both for 64 and 32 bits, with the results you predicted.

Now I must figure out how to proceed in order to design and build my micro-application. I will follow the rest of the tutorial you have pointed to to try to understand the whereabouts this WebBrowser story.

This will be for tomorrow, otherwise my wife is going to kill me ! After 40 years of common life that would be a pitty ;-)


Phil

  • Hero Member
  • *****
  • Posts: 2652
Re: libpq.dylib unreachable ?
« Reply #13 on: May 27, 2018, 08:45:36 pm »
Now I must figure out how to proceed in order to design and build my micro-application. I will follow the rest of the tutorial you have pointed to to try to understand the whereabouts this WebBrowser story.

You can skip that if you don't have any use for TWebBrowser. However, it's a good test of whether you got the Cocoa widgetset compiled okay.

Note that you can continue programming and designing your app with the Carbon widgetset-based Lazarus. Or even on a different system (Linux, Windows). It's just that when you compile on Mac, you need to make sure you use the 64-bit Cocoa widgetset. Either compile with lazbuild as given in the doc, or use the 64-bit Lazarus, which, while not very usable yet, should be able to open a project and compile it okay.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus