Forum > Linux

Shared .so library with TRichMemo component

(1/2) > >>

Dibo:
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

--- End quote ---

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:
Is .so library only works if the host is also written in Lazarus? Because I have this very simple .so:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---static void helloWorld (GtkWidget *wid, GtkWidget *win){    void *handle;    int (*cosine);    char *error;    int x;    handle = dlopen ("/home/dibo/Programowanie/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:
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:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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:

--- Quote from: Dibo on September 14, 2010, 12:24:24 pm ---Python exit without error, so it seems that it found procedure and execute it but nothing happened.

--- End quote ---

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

Navigation

[0] Message Index

[#] Next page

Go to full version