Recent

Author Topic: Cannot connect to MariaDB with ZConnection Component under macOS  (Read 957 times)

Tomki

  • New Member
  • *
  • Posts: 17
Hello all
after a while break I rediscovered Lazarus and try to port older Delphi projects (still from Windows) to Lazarus under macOS and modernize them.
I want to create a client for a MariaDB running on a QNAP NAS.
The DB is set up and I can access it with myPHPAdmin and mySQL Workbench ... so far so good.
I am using a Mac Pro (Intel macOS 12) and a MacBook (M1, macOS 13). I can also access a few other Macs (with Intel CPU) to test things.
Now what happens is this. For starters, I simply try to connect to MariaDB via a ZConnection component of ZEOS. On the Mac Pro, this works without any grumbling. Same project on the MacBook (same Lazarus environment, mySQL installed) and I always get the same error:
"libmysq|client.dylib found but could not be loaded. Check compile-target and library compatibility!. "
I am still in the IDE - nothing compiled. On Mac Pro it works - on all other Macs the error comes.  :oops:
The lib is available. I also copied it to the project folder and also referenced the lib directly with the "LibraryLocation" property. When trying it out, I tried different versions of the mySQLClient.dylib. Always the same error on all Macs except the Mac Pro!!! I can't find any help in the various wikis or forums. Does anyone here have any ideas?
I have attached a screenshot.
Thanks in advance!
« Last Edit: June 05, 2023, 05:35:09 pm by Tomki »

marsupilami79

  • New Member
  • *
  • Posts: 32
Re: Cannot connect to MariaDB with ZConnection Component under macOS
« Reply #1 on: June 06, 2023, 12:51:24 pm »
Hello Tomki,

"libmysq|client.dylib found but could not be loaded. Check compile-target and library compatibility!. "
Zeos will generate that exception if it can find the library but cannot load it for some reason. What happens if you do something like tis:
Code: [Select]
procedure TestLibrayLoading;
var
  Handle: THandle:
begin
  Handle := LoadLibrary(PChar('/Users/thomas/Documents/work/Pascal/sql-test/libmysqlclient.21.dylib'));
  if Handle = 0 then
    RaiseLastOsError
  else
    ShowMessage('Library loaded successfully.');
end;

Maybe this gives some more information on what happens. Also you might want to check if all dependencies of libmysqlclient.21.dylib are available. On Linux one can use ldd to check which other libraries are necessary.

Best regards,

Jan
Zeos developer

Tomki

  • New Member
  • *
  • Posts: 17
Re: Cannot connect to MariaDB with ZConnection Component under macOS
« Reply #2 on: June 07, 2023, 09:28:24 am »
Thanks Jan
I tried and attached you can see the result. But I swear: the file is there!
Regards
Thomas

Zvoni

  • Hero Member
  • *****
  • Posts: 1936
Re: Cannot connect to MariaDB with ZConnection Component under macOS
« Reply #3 on: June 07, 2023, 09:32:58 am »
is the dylib just copied over, or is it compiled for M1 (ARM)?
What's YOUR Compile-Target in your Project?
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Tomki

  • New Member
  • *
  • Posts: 17
Re: Cannot connect to MariaDB with ZConnection Component under macOS
« Reply #4 on: June 07, 2023, 09:33:58 am »
Different question:
I did not only copy the libmysqlclient.21.dylib into the project directory, but all of the *.dylib files. Is there anything else which I need to do?
In a different scenario I pointed the LibraryLocation of the TZConnection component to the /usr/local/ folder in which the mySQL libs were placed at installation.
/usr/local/mysql-8.0.33-macos13-x86_64/lib/libmysqlclient.21.dylib
In this case it works! But I cannot make an application bundle, if it doesn't work if the lib location is different!?
Thomas

Tomki

  • New Member
  • *
  • Posts: 17
Re: Cannot connect to MariaDB with ZConnection Component under macOS
« Reply #5 on: June 07, 2023, 09:35:38 am »
is the dylib just copied over, or is it compiled for M1 (ARM)?
What's YOUR Compile-Target in your Project?

it's just copied from the install directory of mySQL! See above addition...

Tomki

  • New Member
  • *
  • Posts: 17
Re: Cannot connect to MariaDB with ZConnection Component under macOS
« Reply #6 on: June 07, 2023, 09:38:25 am »
is the dylib just copied over, or is it compiled for M1 (ARM)?
What's YOUR Compile-Target in your Project?

compile targets are left on "default".
However, this problem persists on M1 and on Intel based Macs...
The initial setup is identical (as far as I can judge this)
« Last Edit: June 07, 2023, 09:42:49 am by Tomki »

Zvoni

  • Hero Member
  • *****
  • Posts: 1936
Re: Cannot connect to MariaDB with ZConnection Component under macOS
« Reply #7 on: June 07, 2023, 09:42:08 am »
Access-Rights on the dylib itself?
I don't remember anymore on *Nix if you have to set "executable"-Flag and/or Access-Flags if you copy a file from a "protected" Folder
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Tomki

  • New Member
  • *
  • Posts: 17
Re: Cannot connect to MariaDB with ZConnection Component under macOS
« Reply #8 on: June 07, 2023, 09:46:17 am »
I look at the information about both files. See attached.
Sorry, but I am not an expert on "system level"  :o
Difference appears to be the "owner"

Tomki

  • New Member
  • *
  • Posts: 17
Re: Cannot connect to MariaDB with ZConnection Component under macOS
« Reply #9 on: June 07, 2023, 10:35:23 am »
Zvoni, now I think it must have to do with access rights or something like that deep in the system which I don't understand  :(
I copied the lib libmysqlclient.21.dylib from another application into my project folder. I found out that all the libs are contained in the "Frameworks" folder of the mySQLWorkbench application. So I used this one and now I have the following effect:
I point the LibraryLocation to this lib file which I copied from the mySQLWorkbench.app/Frameworks and in the Lazarus Designer I get the same old error message (file found, but can't load) - but if I compile the project (no other change) it work's without error during runtime!?!?!
To me there is no difference in the access rights of the newly copied file, but obviously there must be some difference in the background.
So now, what is the difference and why does it not work in Designtime but in runtime?

TRon

  • Hero Member
  • *****
  • Posts: 1514
Re: Cannot connect to MariaDB with ZConnection Component under macOS
« Reply #10 on: June 07, 2023, 10:42:31 am »
So now, what is the difference and why does it not work in Designtime but in runtime?
It is possible that you installed Lazarus as another user/owner. Some people install/run Lazarus as admin/root/userX (don't ask me why) while you "the normal user" invoked the compiled application from the OS (not through Lazarus). That also applies to/for mariaDB (admin users can do more/other things with the DB manager).

There is a distinct difference in such cases (user access rights). Unfortunately I am not familiar with the platform to such extend that I can make any (additional) suggestions.

Does MacOS has something like the strace utility for Linux ?
« Last Edit: June 07, 2023, 10:52:50 am by TRon »

Tomki

  • New Member
  • *
  • Posts: 17
Re: Cannot connect to MariaDB with ZConnection Component under macOS
« Reply #11 on: June 07, 2023, 11:01:32 am »
Hi TRon
Thank's for your reply, but no, not that I know of  :o

TRon

  • Hero Member
  • *****
  • Posts: 1514
Re: Cannot connect to MariaDB with ZConnection Component under macOS
« Reply #12 on: June 07, 2023, 11:10:35 am »
Hi TRon
Thank's for your reply, but no, not that I know of  :o
Seems it is called dtruss ? or install strace using brew ?

see also: https://stackoverflow.com/questions/73724074/how-to-call-an-equivalent-command-to-strace-on-mac-ideally-from-python (ignore the python parts and what the original question is asking: look at the suggestion for utilities/workarounds to use a trace tool such as strace, dtrace, exesnoop etc though your mileage might vary due to security reasons).

edit: the point in asking is that a utility like strace is able to show you what the application is doing at runtime (loading files/libraries) and what other files the executable drags in during execution (also indirect loading of additional libraries/dependencies/configuration files etc) and report if that succeeded and/or failed. Even something like a tool like a dll dependency walker (on Windows) is able to show the dependencies a library has. It would be able to better pinpoint the issue you seem to be facing. Unless ofc. someone has a better idea ?
« Last Edit: June 07, 2023, 11:22:18 am by TRon »

Tomki

  • New Member
  • *
  • Posts: 17
Re: Cannot connect to MariaDB with ZConnection Component under macOS
« Reply #13 on: June 17, 2023, 07:00:18 pm »
I now tried everything … install_name_tool …. otool … as described and still no success.
Different approach: Did anyone build a macOS app with mysql and a correspomding application bundle? Can any tell me what to do to make the app connect to a mysql (or mariadb server)?
I guess I‘ll open a new threat woth this question…
« Last Edit: June 17, 2023, 09:55:29 pm by Tomki »

 

TinyPortal © 2005-2018