Recent

Author Topic: Dynamic Libraries not loading, just returns 0  (Read 9517 times)

Nafees

  • Jr. Member
  • **
  • Posts: 55
Dynamic Libraries not loading, just returns 0
« on: February 13, 2016, 06:37:50 pm »
I used to program on Windows, but when I switched to Linux (Ubuntu), Dynamic libraries won't load. I've even created a new library (shared library in Linux), and tried to load it, but the LodaLibrary from dynlibs just returns 0. This is my code:

Handle := LoadLibrary(ExFile);
 if Handle=0 then
  ShowMessage('Could not load library: '+#13#10+ExFile+#13#10+
'QIDE will    not function properly.');
 OnSave := TOnSave(GetProcedureAddress(Handle,PChar('OnSave')));

The ShowMessage is triggered, meaning that the library was never loaded. Any ways to solve this?

balazsszekely

  • Guest
Re: Dynamic Libraries not loading, just returns 0
« Reply #1 on: February 13, 2016, 06:40:46 pm »
@Nafees

Please try this(see attachment): http://forum.lazarus.freepascal.org/index.php/topic,31477.msg201742.html#msg201742 . It should work just fine under Windows, Linux, OSX.

Nafees

  • Jr. Member
  • **
  • Posts: 55
Re: Dynamic Libraries not loading, just returns 0
« Reply #2 on: February 13, 2016, 06:46:51 pm »
Still not working.

balazsszekely

  • Guest
Re: Dynamic Libraries not loading, just returns 0
« Reply #3 on: February 13, 2016, 06:50:56 pm »
You should at least download and try it!  :D Same download count as yesterday.

Thaddy

  • Hero Member
  • *****
  • Posts: 14372
  • Sensorship about opinions does not belong here.
Re: Dynamic Libraries not loading, just returns 0
« Reply #4 on: February 13, 2016, 06:58:01 pm »
And you are very, very sure you are not trying to load a windows .dll instead of a linux .so?

Because libraries are not THAT shared, they have different formats. Try what Getmem suggested a little harder...
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: Dynamic Libraries not loading, just returns 0
« Reply #5 on: February 13, 2016, 07:02:32 pm »
You do use unit dynlibs ?

Nafees

  • Jr. Member
  • **
  • Posts: 55
Re: Dynamic Libraries not loading, just returns 0
« Reply #6 on: February 13, 2016, 07:05:57 pm »
I just copied the code, didn't download the zip.

And yes, I compiled it on Linux to a ".so"

And yes, I'm using Dynlibs.

EDIT:
I don't get it, I downloaded your attachment, that code works, but mine is the same as yours (almost), but doesn't work. I attached the files.
« Last Edit: February 13, 2016, 07:13:10 pm by Nafees »

balazsszekely

  • Guest
Re: Dynamic Libraries not loading, just returns 0
« Reply #7 on: February 14, 2016, 01:28:08 am »
@Nafees
You cannot pass managed types(strings for example) across the library(dll, so) boundaries. No wonder your example is not working.

Nafees

  • Jr. Member
  • **
  • Posts: 55
Re: Dynamic Libraries not loading, just returns 0
« Reply #8 on: February 14, 2016, 08:22:38 am »
@Nafees
You cannot pass managed types(strings for example) across the library(dll, so) boundaries. No wonder your example is not working.
But the first procedure (OnSave) should be loaded, and, the library isn't loaded, instead of that specific procedure.

Nafees

  • Jr. Member
  • **
  • Posts: 55
Re: Dynamic Libraries not loading, just returns 0
« Reply #9 on: February 14, 2016, 08:32:46 am »
And how can I send those unmanaged data types?

balazsszekely

  • Guest
Re: Dynamic Libraries not loading, just returns 0
« Reply #10 on: February 14, 2016, 08:36:43 am »
Quote
@Nafees
But the first procedure (OnSave) should be loaded, and, the library isn't loaded, instead of that specific procedure.
Yes, at least the library should be loaded. The only logical explanation is EXFile points to a non existing file. Please debug it!
Here is another example which is more similar to your requirements: http://forum.lazarus.freepascal.org/index.php/topic,30275.msg192494.html#msg192494 . You can see how events + manged types are passed across the library boundaries.
« Last Edit: February 14, 2016, 08:38:39 am by GetMem »

Nafees

  • Jr. Member
  • **
  • Posts: 55
Re: Dynamic Libraries not loading, just returns 0
« Reply #11 on: February 14, 2016, 09:07:11 am »
Quote
@Nafees
But the first procedure (OnSave) should be loaded, and, the library isn't loaded, instead of that specific procedure.
Yes, at least the library should be loaded. The only logical explanation is EXFile points to a non existing file. Please debug it!
Here is another example which is more similar to your requirements: http://forum.lazarus.freepascal.org/index.php/topic,30275.msg192494.html#msg192494 . You can see how events + manged types are passed across the library boundaries.
I've made it sure, the path I provide does point to that library, yet, not working.

balazsszekely

  • Guest
Re: Dynamic Libraries not loading, just returns 0
« Reply #12 on: February 14, 2016, 09:33:31 am »
Then please attach a working example(without binaries) so I can debug it.

Nafees

  • Jr. Member
  • **
  • Posts: 55
Re: Dynamic Libraries not loading, just returns 0
« Reply #13 on: February 14, 2016, 09:48:08 am »
Then please attach a working example(without binaries) so I can debug it.
I've attached it. I haven't defined one procedure in the library which the application uses, but that doesn't affect my problem.

balazsszekely

  • Guest
Re: Dynamic Libraries not loading, just returns 0
« Reply #14 on: February 14, 2016, 10:55:12 am »
First of all the library doesn't even compile. If you want to use forms, frames, etc... you need to add LCL to the required packages and interfaces to the uses clauses. You also need to call application initialize, otherwise nothings gonna work. Secondly the library is loaded as you can see in the attachment, but you cannot call OnSave,  I already explained why in my previous post.

 

TinyPortal © 2005-2018