Compiling Basic Library Project in Linux Fails lazarus / 11-Options ---------------------------------------------------------------------- aurawin · 2008-12-14 17:23 Is there a special thing I need to do to get Lazarus to build an SO on Linux? Installed Laz build : Current (SVN) Installed FPC version : 2.3.1 Sample Code Generates Error MatrixModule.lpr(21) Error: Can't call the linker, switching to external linking ---- Sample Code below ---- library MatrixModule; {$mode objfpc}{$H+} uses   Classes   { you can add units after this }; {$IFDEF WINDOWS}{$R MatrixModule.rc}{$ENDIF}   procedure MyTest; export;   begin   end;   exports MyTest; begin end. ---------------------------------------------------------------------- aurawin · 2008-12-15 00:29 Quote from: "aurawin"Is there a special thing I need to do to get Lazarus to build an SO on Linux? I got the SO to compile with the Compiler Options / Linker stuff all set to "smart" mode.  And it built. TCBMyTest=function(Var Output:TCharArray):boolean; Var   MyTest:TCBMyTest;   MyBuffer:TCharArray; procedure TForm1.OnFormCreate(); begin   FHandle:=LoadLibrary(/complete/path/test.so);   Pointer(MyTest):=DynLibs.GetProcAddress(FLibHandle,'MyTest'); end; procedure TForm1.Button1Click(); begin   MyTest(MyBuffer);   Label1.Caption:=toString(MyBuffer); end; procedure TForm1.Button2Click(); begin   DynLibs.UnloadLibrary(FHandle);  // <--- Raises an External Exception   //and Crashes Lazarus IDE and Application.   // Exception Dialog Project "" raised exception class 'External:SIGSEGV'. end; This Exception is thrown even if I don't access MyTest method in the SO. Any calling conventions that I am supposed to use?  Delphi would not have this problem  in Windoze. ---------------------------------------------------------------------- aurawin · 2008-12-15 01:58 Quote from: "aurawin"Quote from: "aurawin" procedure TForm1.Button2Click(); begin   DynLibs.UnloadLibrary(FHandle);  // <--- Raises an External Exception   //and Crashes Lazarus IDE and Application.   // Exception Dialog Project "" raised exception class 'External:SIGSEGV'. end; The reason the UnloadLibrary fails is because I'm using Dynamic Arrays.  Is there anyone who can tell me the unit I can include that will allow Dynamic Arrays to pass between Libraries and the Main Application? ---------------------------------------------------------------------- Phil · 2008-12-15 04:00 Quote from: "aurawin"Quote from: "aurawin"Quote from: "aurawin" procedure TForm1.Button2Click(); begin   DynLibs.UnloadLibrary(FHandle);  // <--- Raises an External Exception   //and Crashes Lazarus IDE and Application.   // Exception Dialog Project "" raised exception class 'External:SIGSEGV'. end; The reason the UnloadLibrary fails is because I'm using Dynamic Arrays.  Is there anyone who can tell me the unit I can include that will allow Dynamic Arrays to pass between Libraries and the Main Application? In general, you don't pass dynamic structures to and from a library. Stick to simple types like Integer, PChar, etc. Or rather, you can pass dynamic structures (for example, an object cast to an Integer or Pointer), but only work with it on one side of the divide. If you follow this restriction, then you shouldn't have any trouble using a library compiled with Free Pascal, Delphi or C with an app compiled with any of these. Thanks. -Phil ---------------------------------------------------------------------- theo · 2008-12-15 10:22 http://wiki.freepascal.org/shared_library http://courses.cs.vt.edu/~cs3304/FreePascal/doc/prog/node13.html And try with cdecl as calling convention. ---------------------------------------------------------------------- aurawin · 2008-12-16 04:42 Quote from: "theo"http://wiki.freepascal.org/shared_library http://courses.cs.vt.edu/~cs3304/FreePascal/doc/prog/node13.html And try with cdecl as calling convention. I tried declaring both the SO and the App functions as cdecl and the load library works but GetProcAddress can't find the methods.  So I am forced to use stdcall - unless it's just a compiler option I need. ---------------------------------------------------------------------- aurawin · 2008-12-16 04:44 Every time i use the Uses Classes in my Library project file I can load and Use the Library, but I can't unload it without the application crashing. Is there something I need to set or call in my library?  Does it have to do with Initialize/Finalize? I'm not using anything but bare function():boolean Test methods like Startup():boolean and Shutdown():boolean that do nothing but return the boolean value of true. What's the problem?  Any ideas?  The SO unloads provided I don't use any uses in my uses clauses. The only message I received from my console window was Segmentation fault right before the app blew out. ---------------------------------------------------------------------- aurawin · 2008-12-19 02:31 For those who happen on the issue and are following it As of today my understanding is that FPC's finalization method does something with the classes unit that causes this issue. I posted a bug report to see if I can get some help http://mantis.freepascal.org/view.php?id=12814 I'm just trying to use classes in a library that I need to unload and possibly re-load if necessary.