Recent

Author Topic: undefined reference to `TC_SYSTEM_ISLIBRARY'  (Read 7929 times)

xnapoleonx

  • New member
  • *
  • Posts: 9
undefined reference to `TC_SYSTEM_ISLIBRARY'
« on: February 11, 2016, 12:34:45 pm »
Hello,

I'm new to Lazarus and I'm trying to test just the basics.

I installed Lazarus on Linux (Ubuntu).
(1)
Then I created a new project with a form, two button, two edits and one label, and I wrote just two functions:

Code: Pascal  [Select][+][-]
  1. function myadd(a, b : integer): integer;
  2. begin
  3.   Result := a + b;
  4. end;
  5.  
  6. function myminus(a, b : integer): integer;
  7. begin
  8.   Result := a - b;
  9. end;

Really a very simple test, it works fine.

(2)
Then I created a new project " LIBRARY" and wrote just those two functions "myadd" and "myminus".
The project was successfully compiled and the library was created "libmymath.so".
I copied the library to /usr/lib folder and ran ldconfig. (OK)

(3)
Then I created a new project like the first one, with a form, button, etc.. and added the library "libmymath.so"
This was really very simple, and it works fine and without any problem.

Now and after all 3 tests were successful, I installed Lazarus on a Raspberry (Raspian) (Lazarus 1.2.4 & FPC 2.6.4).
I did the same as before:
I was able to create a simple project as (1). It works fine and without any problem.
I was able to create the library "libmymath.so" as (2). No problems.

But the 3. test:
I copied the library to /usr/lib folder and ran ldconfig: OK
I created a new project and added my library as in step (3) and tried to compile the project.
The project was not built and I got the following error:

//usr/lib/libmymath.so: undefined reference to `TC_SYSTEM_ISLIBRARY'

I have no idea what does "TC_SYSTEM_ISLIBRARY" mean, and I'm unable to find any information about it.

Does anybody know what does this error mean?

I would really appreciate your help.
Thank you.

balazsszekely

  • Guest
Re: undefined reference to `TC_SYSTEM_ISLIBRARY'
« Reply #1 on: February 11, 2016, 12:44:46 pm »
Did you linked the library statically? I would try a  dynamically loaded/unloaded approach, during execution

xnapoleonx

  • New member
  • *
  • Posts: 9
Re: undefined reference to `TC_SYSTEM_ISLIBRARY'
« Reply #2 on: February 11, 2016, 01:05:59 pm »
Thank you.

yes, I linked the library statically.
I'll try to dynamically load/unload it.

balazsszekely

  • Guest
Re: undefined reference to `TC_SYSTEM_ISLIBRARY'
« Reply #3 on: February 11, 2016, 01:27:15 pm »
Quote
@xnapoleonx
Thank you.
yes, I linked the library statically.
I'll try to dynamically load/unload it.
You're welcome, something like this(see attachment):

1. Library
Code: Pascal  [Select][+][-]
  1. library libmymath;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5.  
  6. function MyAdd(a, b: Integer): Integer; cdecl;
  7. begin
  8.   Result := a + b;
  9. end;
  10.  
  11. function MyMinus(a, b: Integer): Integer; cdecl;
  12. begin
  13.   Result := a - b;
  14. end;
  15.  
  16. exports
  17.   MyAdd,
  18.   MyMinus;
  19.  
  20. begin
  21. end.

1. Application
Code: Pascal  [Select][+][-]
  1. //...
  2. var
  3.   LibHandle: TLibHandle = NilHandle;
  4.  
  5. procedure TfMain.FormCreate(Sender: TObject);
  6. var
  7.   LibName: String;
  8. begin
  9.  LibName := ExtractFilePath(ParamStr(0)) + 'libmymath.' + SharedSuffix;
  10.  LibHandle := LoadLibrary(LibName);
  11.  if LibHandle = NilHandle then
  12.    ShowMessage('Cannot load library');
  13. end;
  14.  
  15. procedure TfMain.FormDestroy(Sender: TObject);
  16. begin
  17.  if LibHandle <> NilHandle then
  18.  begin
  19.    UnloadLibrary(LibHandle);
  20.    LibHandle := NilHandle;
  21.  end;
  22. end;
  23.  
  24. procedure TfMain.bTestPlusClick(Sender: TObject);
  25. type
  26.   TMyAdd = function(a, b: Integer): Integer; cdecl;
  27. var
  28.   FarProc: TFarProc;
  29.   MyAdd: TMyAdd;
  30. begin
  31.   if LibHandle = NilHandle then
  32.     Exit;
  33.   FarProc := GetProcedureAddress(LibHandle, 'MyAdd');
  34.   if FarProc <> nil then
  35.   begin
  36.     MyAdd := TMyAdd(FarProc);
  37.     ShowMessage(IntToStr(MyAdd(7, 3)));
  38.   end;
  39. end;
  40.  
  41.  
  42. procedure TfMain.bTestMinusClick(Sender: TObject);
  43. type
  44.   TMyMinus = function(a, b: Integer): Integer; cdecl;
  45. var
  46.   FarProc: TFarProc;
  47.   MyMinus: TMyMinus;
  48. begin
  49.   if LibHandle = NilHandle then
  50.     Exit;
  51.   FarProc := GetProcedureAddress(LibHandle, 'MyMinus');
  52.   if FarProc <> nil then
  53.   begin
  54.     MyMinus := TMyMinus(FarProc);
  55.     ShowMessage(IntToStr(MyMinus(7, 3)));
  56.   end;
  57. end;

PS: It should work cross platform way. Works well under ubuntu, I don't have Raspberry to run a few test. Please test it!

xnapoleonx

  • New member
  • *
  • Posts: 9
Re: undefined reference to `TC_SYSTEM_ISLIBRARY'
« Reply #4 on: February 11, 2016, 02:22:01 pm »
unfortunately not, it does not work.

LoadLibrary returns NilHandle.
GetLoadErrorStr returns an empty string.

I tried it with:
(1) LibName = 'libmymath.so'
(2) LibName = <absolute path>'/libmymath.so'
(3) LibName = ExtractFilePath(ParamStr(0)) + 'libmymath.' + SharedSuffix (= (2))

balazsszekely

  • Guest
Re: undefined reference to `TC_SYSTEM_ISLIBRARY'
« Reply #5 on: February 11, 2016, 02:27:57 pm »
@xnapoleonx
Then must be some Raspberry specific stuff, because I just tested under windows(32/64), linux, osx. Works fine.

PS: Please do a quick google search, maybe there is some documented issue with the libraries under Raspberry.
« Last Edit: February 11, 2016, 02:33:06 pm by GetMem »

xnapoleonx

  • New member
  • *
  • Posts: 9
Re: undefined reference to `TC_SYSTEM_ISLIBRARY'
« Reply #6 on: February 11, 2016, 02:46:56 pm »
Yes, I think so.

I think , the problem is not how to load/unload the library. I think it is the way how the library is created!
The error "//usr/lib/libmymath.so: undefined reference to `TC_SYSTEM_ISLIBRARY'" maybe means that this `TC_SYSTEM_ISLIBRARY' is within the library not defined.

While creating a library, is there any option/settings/etc. to tell the compiler, that this is a library? Or to define this unknown `TC_SYSTEM_ISLIBRARY'?


balazsszekely

  • Guest
Re: undefined reference to `TC_SYSTEM_ISLIBRARY'
« Reply #7 on: February 11, 2016, 03:13:59 pm »
Quote
While creating a library, is there any option/settings/etc. to tell the compiler, that this is a library? Or to define this unknown `TC_SYSTEM_ISLIBRARY'?
Not that I am aware of.

I found the, following links(just search for: TC_SYSTEM_ISLIBRARY):
     http://zengl.googlecode.com/svn/branches/0.3.x/src/zgl_application.pas
     https://fossies.org/diffs/fpcbuild/2.6.4_vs_3.0.0/fpcsrc/rtl/linux/arm/dllprt0.as-diff.html (what is you fpc version?)
Unfortunately is still a mistery what TC_SYSTEM_ISLIBRARY is. I searched the FPC/Lazarus folders, found nothing. Let's wait, maybe somebody has a better idea.

xnapoleonx

  • New member
  • *
  • Posts: 9
Re: undefined reference to `TC_SYSTEM_ISLIBRARY'
« Reply #8 on: February 11, 2016, 03:25:26 pm »
I just copied a library from "/usr/lib' to my project folder and tried to load it dynamically: YES IT WORKS.
So I think, it is really how the library is created!


FPC Version: 2.6.4
« Last Edit: February 11, 2016, 03:28:52 pm by xnapoleonx »

balazsszekely

  • Guest
Re: undefined reference to `TC_SYSTEM_ISLIBRARY'
« Reply #9 on: February 11, 2016, 03:33:00 pm »
Quote
So I think, it is really how the library is created!
Yes it's possible! Or perhaps some privilege issue?

xnapoleonx

  • New member
  • *
  • Posts: 9
Re: undefined reference to `TC_SYSTEM_ISLIBRARY'
« Reply #10 on: February 11, 2016, 06:20:12 pm »
Your library, as I downloaded it:

pi@raspberrypi:~ $ file /home/pi/Downloads/Library/libmymath.so
/home/pi/Downloads/Library/libmymath.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, not stripped

pi@raspberrypi:~ $ nm -DC /home/pi/Downloads/Library/libmymath.so
00006200 T MyAdd
00006210 T MyMinus


I re-compiled it (on Raspberry)

pi@raspberrypi:~ $ file /home/pi/Downloads/Library/Library/libmymath.so
/home/pi/Downloads/Library/Library/libmymath.so: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, not stripped

pi@raspberrypi:~ $ nm -DC /home/pi/Downloads/Library/Library/libmymath.so
0000472c T MyAdd
00004730 T MyMinus
                 U TC_SYSTEM_ISLIBRARY

After I re-compiled it, the symbol "TC_SYSTEM_ISLIBRARY" was added!?

balazsszekely

  • Guest
Re: undefined reference to `TC_SYSTEM_ISLIBRARY'
« Reply #11 on: February 11, 2016, 06:25:44 pm »
Ok.. at least we know this :),  but I suppose the loading still not works?

PS: Can you please try to change the permission of that library?
« Last Edit: February 11, 2016, 06:29:12 pm by GetMem »

xnapoleonx

  • New member
  • *
  • Posts: 9
Re: undefined reference to `TC_SYSTEM_ISLIBRARY'
« Reply #12 on: February 11, 2016, 06:59:18 pm »
I changed the permission using the command "chmod 777" to

-rwxrwxrwx 1 pi pi   390376 Feb 11 18:05 libmymath.so

and still not works!

xnapoleonx

  • New member
  • *
  • Posts: 9
Re: undefined reference to `TC_SYSTEM_ISLIBRARY'
« Reply #13 on: February 12, 2016, 09:14:10 pm »
It is a Lazarus/FPC bug.  :(
If the library was created with FPC (ARMHF) on Raspberry, then it is not possible to load the library with Lazarus/FPC.

I installed FPC 3.1.1 and Lazarus 1.7 on Raspberry => STILL DOES NOT WORK.
The TC_SYSTEM_ISLIBRARY error is not shown any more.
But GetLoadErrorStr returns ".....can not open file...file or folder not found.."

It is possible to load other libraries (not created with FPC)  :o

balazsszekely

  • Guest
Re: undefined reference to `TC_SYSTEM_ISLIBRARY'
« Reply #14 on: February 12, 2016, 09:21:20 pm »
Quote
@xnapoleonx
It is a Lazarus/FPC bug.  :(
Then please report it on the bugtracker: http://bugs.freepascal.org/main_page.php

Quote
It is possible to load other libraries (not created with FPC)
As a temporary solution, can you create the library in some other language?

 

TinyPortal © 2005-2018