Shared .so library with TRichMemo component lazarus / 32-Linux ---------------------------------------------------------------------- Dibo · 2010-09-13 18:22 Hi, I can open LCL form in dll library on Windows, but I have a problem with .so library on Linux. When I put TRichMemo component on empty form and try to compile project I get this error: Quote/usr/bin/ld: /home/dibo/Programowanie/Lazarus/components/richmemo /lib/x86_64-linux/richmemo.o: relocation R_X86_64_32S against `TC_RICHMEMO_RTFLOADSTREAM' can not be used when making a shared object; recompile with -fPIC /home/dibo/Programowanie/Lazarus/components/richmemo/lib/x86_64- linux/richmemo.o: could not read symbols: Bad value Compiling with -fPIC switch doesn't help. Project with empty form is compiling without errors. Ubuntu 10.4 64bit. Lazarus 0.9.29 from SVN revision 27282. FPC 2.5.1 from SVN revision 100908. Regards. ---------------------------------------------------------------------- Dibo · 2010-09-13 20:49 Is .so library only works if the host is also written in Lazarus? Because I have this very simple .so: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i library project1; {$mode objfpc}{$H+} {$R *.res} function testresult: Integer; cdecl; export;begin  Result := 10;end; exports testresult; beginend. And host in GCC (i don't know C++ so I found demo howto load library) Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i static void helloWorld (GtkWidget *wid, GtkWidget *win){    void *handle;    int (*cosine);    char *error;    int x;    handle = dlopen ("/home/dibo/P rogramowanie/codeblocsk/test/Test/bin/Debug/libproject1.so", RTLD_LAZY);    if (!handle) {        fprintf (stderr, "%s\n", dlerror());        exit(1);    }    dlerror();    /* Clear any existing error */    cosine = dlsym(handle, "testresult");    if ((error = dlerror()) != NULL)  {        fprintf (stderr, "%s\n", error);        exit(1);    }    x = (*cosine);    printf ("%d\n", x);    dlclose(handle);    return 0;} It found .so and "testresult" function but this function result some -456766 value instead of 10 ---------------------------------------------------------------------- JuhaManninen · 2010-09-14 09:06 64-bit is the problem now. Pascal and C have different default sizes for integer types. C always uses the native register size, Pascal uses max 32 bits for Integer and Cardinal. Solution: use PtrInt and PtrUInt instead. They match with C types. There may be other potential problems with 64-bit. I only know this one. Juha ---------------------------------------------------------------------- Dibo · 2010-09-14 10:24 Hm, it's probably a different problem, because i create procedure in .so which create some text file. This work on host written in Lazarus. But on C++ and python doesn't work: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i library project1; {$mode objfpc}{$H+} uses  Classes; {$R *.res} procedure CreateCustomFile; cdecl; export;var  s: TStringList;begin  s := TStringList.Create;  try    s.Add('sdfsdf');    s.SaveToFile('/home/dibo/test.txt');  finally    s.Free;  end;end; exports CreateCustomFile; beginend.  Code: Python  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i import ctypeslibc = ctypes.cdll.LoadLibrary("/home/dibo/Programowanie/Lazarus /Projects/archiwum_r/test_dll/dcu/libproject1.so") # doctest: +LINUXlibc.CreateCustomFile Python exit without error, so it seems that it found procedure and execute it but nothing happened. ---------------------------------------------------------------------- JuhaManninen · 2010-09-14 11:05 Quote from: Dibo on September 14, 2010, 12:24:24 pmPython exit without error, so it seems that it found procedure and execute it but nothing happened. Have you tested with some similar shared library made with C, to isolate the problem? I guess you have... cdecl; export;  is somehow not enough. You should ask fpc-pascal mailing list for more advice. Juha ---------------------------------------------------------------------- Dibo · 2010-09-14 11:24 Quote from: JuhaManninen on September 14, 2010, 01:05:11 pmQuote from: Dibo on September 14, 2010, 12:24:24 pmPython exit without error, so it seems that it found procedure and execute it but nothing happened. Have you tested with some similar shared library made with C, to isolate the problem Yes, I created test .so in GCC and it works in python and lazarus host. ---------------------------------------------------------------------- Dibo · 2010-09-14 14:35 Ehhh, problem was that I call libc.CreateCustomFile instead of libc.CreateCustomFile() . From today, I love Pascal syntax more. But I still have problem posted on first topic (when on form is TRichMemo). ---------------------------------------------------------------------- JuhaManninen · 2010-09-14 15:57 You could ask also from lazarus mailing list if  TRichMemo has something preventing it to work from a shared lib. There may not be many people who know this and they maybe read the mailing list instead of forum. Juha ---------------------------------------------------------------------- Dibo · 2010-09-14 16:13 Ok. I do