Lazarus

Programming => Databases => Topic started by: rwebb616 on February 23, 2021, 05:44:11 pm

Title: [SOLVED] Lazarus refuses to load libmysql.dll
Post by: rwebb616 on February 23, 2021, 05:44:11 pm
Hello,

I'm not sure how to fix this - I have Lazarus installed on one computer and everything with libmysql is working - I can connect/query my database and fill a dbgrid successfully.  I have the same version of lazarus and the libmysql.dll on another computer both having the same bitness on operating system (windows 10) and Lazarus keeps giving me the error "cannot load default mysql library (libmysql.dll) check your installation".

I have the DLL in the system path and just typing the name of the dll at the command line brings up an error saying it needs an application to load the dll which indicates to me that it is found in the path.  I also have the DLL in the project directory and also in the c:\lazarus directory.

What am I missing?

EDIT:  I also forgot to mention that I installed MariaDB which comes with HeidiSQL and I can use Heidi to access the database that I'm trying to access in Lazarus using the libmysql.dll (in the dropdown in heidi) and connect just fine.

Rich
Title: Re: Lazarus refuses to load libmysql.dll
Post by: MarkMLl on February 23, 2021, 07:28:34 pm
I don't know whether this is going to be any help. I'm not a Windows user but I've been on the periphery of some (networking) problems which turned out to be caused by Windows 10 having been installed/upgraded on different days: various system defaults in the installation download were changed a few months after it became available, and I can't remember whether there was anything useful in the OS version number that indicated its history.

So two Windows 10 systems might not be quite as identical as one assumes.

MarkMLl
Title: Re: Lazarus refuses to load libmysql.dll
Post by: rwebb616 on February 23, 2021, 07:55:51 pm
I'm not sure that it's really Windows related... The message comes back immediately when I change the connected property on the connection from false to true.  It doesn't even look like Lazarus is attempting to load it so I'm missing something probably really simple.  I don't remember having to add any packages to Lazarus or anything - it supposedly supports mysql 5.7 out of the box so just having the client library somewhere in the path and in the project folder seems like it would be sufficient.  I also have it in the root lazarus folder for good measure.  I've also tried downloading the mysql 5.7.32 x64 zip file and putting it's lib folder in the path - same thing.

I also tried replacing it with the dll from the mariadb lib folder that heidi SQL is using .. nothing I do seems to make any difference.  This seems very odd to me.
Title: Re: Lazarus refuses to load libmysql.dll
Post by: GetMem on February 23, 2021, 08:01:41 pm
If you run the following code, what message is displayed? First make sure the exe and dll are in the same folder.
Code: Pascal  [Select][+][-]
  1. uses Windows;
  2.  
  3. procedure TForm1.Button1Click(Sender: TObject);
  4. var
  5.   LibName: WideString;
  6.   LibHandle: TLibHandle = NilHandle;
  7. begin
  8.   LibName := WideString(ExtractFilePath(ParamStr(0)) + 'libmysql.dll');
  9.   LibHandle := LoadLibraryW(PWideChar(LibName));
  10.   if LibHandle = NilHandle then
  11.     ShowMessage(SysErrorMessage(GetLastError))
  12.   else
  13.     ShowMessage('Library successfully loaded!');
  14. end;
Title: Re: Lazarus refuses to load libmysql.dll
Post by: rwebb616 on February 23, 2021, 08:07:50 pm
I get "The specified module could not be found" - put the libmysql.dll in the same folder as the project and the .exe.

It's also in the path.  Strange?
Title: Re: Lazarus refuses to load libmysql.dll
Post by: GetMem on February 23, 2021, 08:11:41 pm
1. Make sure the bitness are the same
2. Disable AV software
3. Run the exe with elevated permissions

If still not works, please upload the dll somewhere so I can run a few tests.
Title: Re: Lazarus refuses to load libmysql.dll
Post by: rwebb616 on February 23, 2021, 08:13:48 pm
Just for the heck of it I put the 32 bit version in the folder and now the showmessage box comes up blank which looks like it would be nilhandle but for some reason no message.  I also tried that dll with my test app and get the same error about not being able to load. 

I've tried several different versions of the mysql dll including the one that works on my other machine.

Title: Re: Lazarus refuses to load libmysql.dll
Post by: rwebb616 on February 23, 2021, 08:19:51 pm
Here is the one from my working machine:  https://files.crossfirechurch.org/index.php/s/xp4NtqL3hbF4Cec
Title: Re: Lazarus refuses to load libmysql.dll
Post by: GetMem on February 23, 2021, 08:29:28 pm
Your dll is loaded without any issues at my side. Something must be wrong with your windows. A system dll can be loaded?
Code: Pascal  [Select][+][-]
  1. //...
  2. LibName := WideString('ntdll.dll');
  3. //...

Title: Re: Lazarus refuses to load libmysql.dll
Post by: rwebb616 on February 23, 2021, 08:37:35 pm
Ah yes... same error "The specified module could not be found" what on earth... this is a fairly fresh install of windows too.  How is it that it works with Heidi SQL though...

Also I just went through and made sure the only copy of the dll is in the folder with the EXE .. removed all system paths with the dll in it - same issue.

Windows Version 1909
Title: Re: Lazarus refuses to load libmysql.dll
Post by: rwebb616 on February 23, 2021, 09:03:10 pm
Tried using regsvr32 on the dll and got this error as well.  Something is wrong somewhere!
Title: Re: Lazarus refuses to load libmysql.dll
Post by: rwebb616 on February 23, 2021, 09:13:47 pm
Are there any c runtime libraries or anything like that I need to install?  .net frameworks?
Title: Re: Lazarus refuses to load libmysql.dll
Post by: GetMem on February 23, 2021, 09:25:36 pm
Try this:
cmd(Run as administrator)->sfc /scannow
Title: Re: Lazarus refuses to load libmysql.dll
Post by: rwebb616 on February 23, 2021, 09:25:51 pm
All fixed - had to install all of the VC++ redistributables and the VC Runtime libraries.  After those were installed it started working! Thanks GetMem for your help - that drove me to look for the runtimes - downloaded dependency walker and found out why they weren't loading.

Rich
Title: Re: Lazarus refuses to load libmysql.dll
Post by: MarkMLl on February 23, 2021, 09:26:39 pm
Is the DLL corrupt? The message could be interpreted as either "can't find it" or "it's not a DLL".

I'd not have expected any other prerequisites from the POV of the Lazarus program. From the POV of the DLL... there's always the possibility that the developers have tried to do something clever in the version you've got.

MarkMLl
Title: Re: Lazarus refuses to load libmysql.dll
Post by: GetMem on February 23, 2021, 09:27:26 pm
All fixed - had to install all of the VC++ redistributables and the VC Runtime libraries.  After those were installed it started working! Thanks GetMem for your help - that drove me to look for the runtimes - downloaded dependency walker and found out why they weren't loading.

Rich
Ok. I'm glad it's working. :)
Title: Re: [SOLVED] Lazarus refuses to load libmysql.dll
Post by: rwebb616 on February 23, 2021, 09:28:09 pm
Perhaps the libmysql.dll depends on one of the runtimes... the specific file that dependency walker was choking on was msvcr120.dll
Title: Re: [SOLVED] Lazarus refuses to load libmysql.dll
Post by: af0815 on February 23, 2021, 09:29:34 pm
it looks if the dll have depencies, not fullfilled on a fresh system.
Title: Re: [SOLVED] Lazarus refuses to load libmysql.dll
Post by: rwebb616 on February 23, 2021, 09:31:35 pm
it looks if the dll have depencies, not fullfilled on a fresh system.

Yes and I am sure the runtimes were installed on the other system because I also have Visual Studio Community installed so the runtimes probably got installed with that.  The msvcr120.dll appears to be part of the Visual C runtime for Visual Studio 2013.
Title: Re: [SOLVED] Lazarus refuses to load libmysql.dll
Post by: dseligo on February 24, 2021, 12:18:54 pm
You could try libmysql.dll from HeidiSQL installation, it probably doesn't have dependency.
Title: Re: [SOLVED] Lazarus refuses to load libmysql.dll
Post by: rwebb616 on March 04, 2021, 02:07:47 am
I did try this but it's version 5.6 so I didn't get the error about the specified module but got expected version 5.7 and got version 5.6 so it looks like it maybe is statically linked with all the dependencies - and it did appear to work with the 5.6 connection object.

Rich
TinyPortal © 2005-2018