Lazarus
Programming => Operating Systems => Linux => Topic started by: Nafees 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?
-
@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.
-
Still not working.
-
You should at least download and try it! :D Same download count as yesterday.
-
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...
-
You do use unit dynlibs ?
-
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.
-
@Nafees
You cannot pass managed types(strings for example) across the library(dll, so) boundaries. No wonder your example is not working.
-
@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.
-
And how can I send those unmanaged data types?
-
@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.
-
@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.
-
Then please attach a working example(without binaries) so I can debug it.
-
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.
-
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.
-
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.
Where do I call Application.Initialize? Because I will be creating the same frame many times, do I call it just once or everytime?
-
@Nafees
Where do I call Application.Initialize? Because I will be creating the same frame many times, do I call it just once or everytime?
Only once. This plugin like library topic was also covered here(Plugin.zip): http://forum.lazarus.freepascal.org/index.php/topic,30252.msg192411.html#msg192411 :D
-
@Nafees
Where do I call Application.Initialize? Because I will be creating the same frame many times, do I call it just once or everytime?
Only once. This plugin like library topic was also covered here(Plugin.zip): http://forum.lazarus.freepascal.org/index.php/topic,30252.msg192411.html#msg192411 :D
I think it's a Ubuntu releated bug. That attachment also isn't loading the library, LibHandle is still nil after loading the library.
-
I think it's a Ubuntu releated bug. That attachment also isn't loading the library, LibHandle is still nil after loading the library.
Is loading fine at my side, I'm also using ubuntu 14.04 LTS.
-
I think it's a Ubuntu releated bug. That attachment also isn't loading the library, LibHandle is still nil after loading the library.
Is loading fine at my side, I'm also using ubuntu 14.04 LTS.
I also have the same version.
-
@Nafees
Here is the proof:
https://youtu.be/f1iq0iSjIho
-
@Nafees
Here is the proof:
https://youtu.be/f1iq0iSjIho
I didn't meant to say that I doubt you. I think I know why it won't work with me: I'm new to lazarus and don't know how to add lcl to the packages. Do you just put lcl in uses or is it somewhere from the IDE?
EDIT: Solved the whole problem. The problem was that LCL package, just found out how to add it.
EDIT: I successfully loaded a dummy library, but that "plugin" library still won't load. Now, it gives this error on LoadLibrary:
Project QIDE raised exception class 'External: SIGSEGV'.
In file './include/winapi.inc' at line 621
Any ideas why this is caused? I still remember it was fairly easy to do this on Delphi, but Delphi isn't on Linux.
EDIT: Fixed that too.