Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-02

Problems linking C library on Linux (*.so & *.a files)

13 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Guillermo Martínez Jiménez

Hello.

I'm trying to link a library written in C (Allegro 4.2) on Linux. The testing program (which is minimal) links without problems but it raises a runtime error:

#~/test: ./test
./test: symbol lookup error: /usr/local/lib/liballeg.so.4.2: undefined symbol: _blender_trans24
#~/test:

I've emailed to the library developers and they said "You'll have to find some way to work around it, e.g. link your bindings with liballeg_unshareable.a and make sure when you dlopen() it can resolve those symbols.".

I tried to link that library using "{$linklib alleg_unsharable}". It linked without error but it raises the same runtime error. Then I tried deleting the "{$...}" and adding "-klalleg_unsharable" at command line but then it said:

...
/usr/bin/ld: lalleg_unsharable: No such file: No such file or directory

  test.pp(17,1) Error: Error while linking

...

The file "liballeg_unsharable.a" exists at "/usr/local/lib" so I added "-Fl/usr/local/lib" at command line but it returns the same error.

What can I do?

I'm using FPC 2.2.2 on Xubuntu 8.04. No Lazarus nor make.

Reply by email

Jonas Maebe
to Guillermo Martínez Jiménez
Guillermo Martínez Jiménez wrote 10 lines
I tried to link that library using "{$linklib alleg_unsharable}". It linked without error but it raises the same runtime error. Then I tried deleting the "{$...}" and adding "-klalleg_unsharable" at command line but then it said: ... /usr/bin/ld: lalleg_unsharable: No such file: No such file or directory test.pp(17,1) Error: Error while linking ...

Linking with a static library works the same way as linking with an object file: Either -k/full/path/to/library.a, or {$l library.a} in combination with -Fo/full/path/to/library.

In principle, {$linklib xxx} or -klxxx in combination with -Fl would also work if you use the -Xt parameter (so the linker looks for static libraries -- but then it will try to link every single library statically, which is probably not what you want).

Jonas

Reply by email

Guillermo Martínez Jiménez

Thanks for the advices, Jonas. I've tried all the combinations but allways it returns the same runtime error.

The library developers tells me it is a known issue and it should be fixed on the next stable release.

I think I must use the dynlibs unit, which seems to work.

Thanks anyway. I somebody finds another workarround, please tell me.

Greetings.

Guillermo Martinez.

Show quoted text 260 lines
On 10 Feb 2009, at 19:30, Guillermo Martínez Jiménez wrote: > I tried to link that library using "{$linklib alleg_unsharable}". It > linked without error but it raises the same runtime error. Then I > tried deleting the "{$...}" and adding "-klalleg_unsharable" at > command line but then it said: > > ... > /usr/bin/ld: lalleg_unsharable: No such file: No such file or > directory > test.pp(17,1) Error: Error while linking > ... Linking with a static library works the same way as linking with an object file: Either -k/full/path/to/library.a, or {$l library.a} in combination with -Fo/full/path/to/library. In principle, {$linklib xxx} or -klxxx in combination with -Fl would also work if you use the -Xt parameter (so the linker looks for static libraries -- but then it will try to link every single library statically, which is probably not what you want). Jonas ------------------------------ Message: 2 Date: Tue, 10 Feb 2009 15:36:41 -0700 From: "Ken G. Brown" Subject: [fpc-pascal] documentation for file handling, reset, rewrite, errors? To: Message-ID: Content-Type: text/plain; charset="us-ascii" I cannot seem to find the good docs for the file handling routines assign, rewrite and reset in the pdf's that came with fpc-2.2.2. Where might the best ones be? I have: User's Manual.pdf Units Reference Guide.pdf Programmer's Manual.pdf Language Reference Guide.pdf Free Component Library.pdf Compiler Switches.pdf Code Documented.pdf I would like to find good descriptions of how they work, along with error handling and examples of how to how to best use them. eg. can an internal memory based file be set to be written and read at the same time? Is the file read position independent of the write position? If the internal file has been written to the end and the write operation is finished but the file is still open for writing, what needs to be done in order to start reading the file from the beginning? Are streams available for reading and writing and are they preferable to while not eof (inFi) read(inFi) then write(outFi)? Are exceptions useful? Examples? My goal is to create an internal file then dump it to a system usb printer. I've found an example of writing to a pipe using assignlst (f,'|/usr/bin/lpr -m'); that seems to sorta work, from here: <http://ubuntuforums.org/showthread.php?t=656110>, 2nd message. Is that a good way to do output to a printer? Thx again for any pointers. Ken G. Brown ------------------------------ Message: 3 Date: Wed, 11 Feb 2009 09:37:09 +0100 (CET) From: Michael Van Canneyt Subject: Re: [fpc-pascal] documentation for file handling, reset, rewrite, errors? To: FPC-Pascal users discussions Message-ID: Content-Type: TEXT/PLAIN; charset=US-ASCII On Tue, 10 Feb 2009, Ken G. Brown wrote: > I cannot seem to find the good docs for the file handling routines assign, rewrite and reset in the pdf's that came with fpc-2.2.2. Where might the best ones be? > I have: > User's Manual.pdf > Units Reference Guide.pdf Normally, the routines are documented here. > Programmer's Manual.pdf > Language Reference Guide.pdf > Free Component Library.pdf > Compiler Switches.pdf > Code Documented.pdf > > I would like to find good descriptions of how they work, along with error handling and examples of how > to how to best use them. > > eg. can an internal memory based file be set to be written and read at the same time? Yes. > Is the file read position independent of the write position? This kind of thing is not explained. > > If the internal file has been written to the end and the write operation is finished but > the file is still open for writing, what needs to be done in order to start reading the file from the beginning? With standard file I/O, this is not possible. > > Are streams available for reading and writing and are they preferable to while not eof (inFi) read(inFi) > then write(outFi)? They are. > > Are exceptions useful? Yes :-) > > Examples? > > My goal is to create an internal file then dump it to a system usb printer. >From your questions, I think you're better off using TMemoryStream and class based programs. They're more flexible than the standard Pascal file I/O. > > I've found an example of writing to a pipe using assignlst (f,'|/usr/bin/lpr -m'); that seems to sorta work, > from here: <http://ubuntuforums.org/showthread.php?t=656110>, 2nd message. > Is that a good way to do output to a printer? On linux/unix there is no other reliable way. Michael. ------------------------------ Message: 4 Date: Wed, 11 Feb 2009 16:03:25 +0700 From: Bee Subject: [fpc-pascal] REQ: official FPC's FCGI framework To: FPC-Pascal users discussions Message-ID: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Hi all, FPC has pretty usable support for web based development. Currently FPC supports it through CGI and Apache module. IMO, there's one more support that should be added officially: FastCGI. The initial work has been done by ExtPascal project. But, somehow I found it a bit problematic if it's compiled by FPC on non-Windows platform, especially with thread-related. Hence, I now request for official support from FPC to provide FCGI framework as the third alternative for web based application development. Later, this official framework could be used as alternative FCGI framework for ExtPascal project. What do you think? TIA. -Bee- ------------------------------ Message: 5 Date: Wed, 11 Feb 2009 10:19:41 +0100 (CET) From: Michael Van Canneyt Subject: Re: [fpc-pascal] REQ: official FPC's FCGI framework To: FPC-Pascal users discussions Message-ID: Content-Type: TEXT/PLAIN; charset=US-ASCII On Wed, 11 Feb 2009, Bee wrote: > Hi all, > > FPC has pretty usable support for web based development. Currently FPC > supports it through CGI and Apache module. IMO, there's one more support that > should be added officially: FastCGI. The initial work has been done by > ExtPascal project. But, somehow I found it a bit problematic if it's compiled > by FPC on non-Windows platform, especially with thread-related. > > Hence, I now request for official support from FPC to provide FCGI framework > as the third alternative for web based application development. Later, this > official framework could be used as alternative FCGI framework for ExtPascal > project. > > What do you think? TIA. I see no reason why this could not be done. Will you coordinate the efforts? Michael. ------------------------------ Message: 6 Date: Wed, 11 Feb 2009 01:26:28 -0800 (PST) From: leledumbo Subject: Re: [fpc-pascal] Origin of FPC features To: Message-ID: Content-Type: text/plain; charset=us-ascii I see there are quite a lot of differences from my guessing, I'll fix them up. When I have time, I'll also add it to the wiki. Thanks for all your replies. -- View this message in context: http://www.nabble.com/Origin-of-FPC-features-tp21927731p21951053.html Sent from the Free Pascal - General mailing list . ------------------------------ Message: 7 Date: Wed, 11 Feb 2009 16:29:13 +0700 From: Bee Subject: Re: [fpc-pascal] REQ: official FPC's FCGI framework To: FPC-Pascal users discussions Message-ID: Content-Type: text/plain; charset=ISO-8859-1; format=flowed > I see no reason why this could not be done. Will you coordinate the efforts? I'd like to help, especially on testing and bug fixing. But I don't think I have enough knowledge about threading and FCGI internal work. I need people who have the expertise on those 2 fields to do the initial work. ExtPascal author (Wanderlan) doesn't seem very interested to support non Windows platform as he mostly works on Windows (using Delphi). I'm also quite active in ExtPascal project though mostly on testing and bug fixing but I don't do much on the real coding work. Some enhancement suggestions are also came as my request (CGI gateway, Mac support, enumeration, etc). I can help on the same things here. -Bee- ------------------------------ _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal End of fpc-pascal Digest, Vol 56, Issue 16 ******************************************

Reply by email

Jonas Maebe
to Guillermo Martínez Jiménez
Guillermo Martínez Jiménez wrote 25 lines
> On 10 Feb 2009, at 19:30, Guillermo Martínez Jiménez wrote: > >> I tried to link that library using "{$linklib alleg_unsharable}". It >> linked without error but it raises the same runtime error. Then I >> tried deleting the "{$...}" and adding "-klalleg_unsharable" at >> command line but then it said: >> >> ... >> /usr/bin/ld: lalleg_unsharable: No such file: No such file or >> directory >> test.pp(17,1) Error: Error while linking >> ... > > Linking with a static library works the same way as linking with an > object file: Either -k/full/path/to/library.a, or {$l library.a} in > combination with -Fo/full/path/to/library. > > In principle, {$linklib xxx} or -klxxx in combination with -Fl would > also work if you use the -Xt parameter (so the linker looks for > static > libraries -- but then it will try to link every single library > statically, which is probably not what you want). Thanks for the advices, Jonas. I've tried all the combinations but allways it returns the same runtime error.

Link time error, I guess. But according to your original message, the name of the library is liballeg_unshareable.a. So you would have to use -k liballeg_unshareable.a, not "-klalleg_unshareable.a". The linker only prepends "lib" if you use "-k-lalleg_unshareable.a" (note the extra "-"). And if you use it with {$l } in the source, you also need the full exact name: {$l liballeg_unshareable.a} (because you are linking like a regular object file in that case, not as a library).

Jonas

Reply by email

Guillermo Martínez Jiménez
to Jonas Maebe
Show quoted text 9 lines
Link time error, I guess. But according to your original message, the name of the library is liballeg_unshareable.a. So you would have to use -k liballeg_unshareable.a, not "-klalleg_unshareable.a". The linker only prepends "lib" if you use "-k-lalleg_unshareable.a" (note the extra "-"). And if you use it with {$l } in the source, you also need the full exact name: {$l liballeg_unshareable.a} (because you are linking like a regular object file in that case, not as a library).

I've used this command line:

fpc test.pp -Fu../lib/ -k/usr/local/lib/liballeg_unsharable.a

Not link time error but run time error. Tried also {$l liballeg_unsharable.a} at sources and the same: not link time error but run time error.

Now I'm trying using dynlibs unit.

Reply by email

Guillermo Martínez Jiménez
Perhaps I missed it, but are you sure you declared the functions/procedure in the library you are using cdecl? That would explain a runtime error instead of linker error.

I'm sure I've used "cdecl" to declare the procedure I'm using to test it.

By the way, Allegro's developers confirm me the requested symbol isn't in the shared librery but it's in the static one and they're now looking for a way to have all the library in one shared file. It is one of the objectives for their next release.

Guillermo "Ñuño" Martínez

Reply by email

Jonas Maebe
to Guillermo Martínez Jiménez: I've used this command line: fpc test.pp -Fu../lib/ -k/usr/local/lib/liballeg_unsharable.a
Guillermo Martínez Jiménez wrote 20 lines
> Link time error, I guess. But according to your original message, > the name > of the library is liballeg_unshareable.a. So you would have to use -k > liballeg_unshareable.a, not "-klalleg_unshareable.a". The linker only > prepends "lib" if you use "-k-lalleg_unshareable.a" (note the extra > "-"). > And if you use it with {$l } in the source, you also need the full > exact > name: {$l liballeg_unshareable.a} (because you are linking like a > regular > object file in that case, not as a library). > I've used this command line: fpc test.pp -Fu../lib/ -k/usr/local/lib/liballeg_unsharable.a Not link time error but run time error. Tried also {$l liballeg_unsharable.a} at sources and the same: not link time error but run time error.

Maybe the problem is that the default FPC config file enables symbol stripping. So even though the routines from the library are in your program, dynamically loaded libraries won't be able to find them since the symbol names are gone. Try compiling the program with -Xs- to disable symbol stripping.

Jonas

Reply by email

Guillermo Martínez Jiménez
Show quoted text 7 lines
From: Jonas Maebe Maybe the problem is that the default FPC config file enables symbol stripping. So even though the routines from the library are in your program, dynamically loaded libraries won't be able to find them since the symbol names are gone. Try compiling the program with -Xs- to disable symbol stripping.

That's a good tip. That's logic, because I don't use that symbol directly.

Thanks. I'll try it. Unfortunately I can't do it until Wednesday.

Guillermo "Ñuño" Martínez.

Reply by email

Jonas Maebe
to Guillermo Martínez Jiménez
Guillermo Martínez Jiménez wrote 11 lines
> From: Jonas Maebe > > Maybe the problem is that the default FPC config file enables symbol > stripping. So even though the routines from the library are in your > program, dynamically loaded libraries won't be able to find them > since > the symbol names are gone. Try compiling the program with -Xs- to > disable symbol stripping. That's a good tip. That's logic, because I don't use that symbol directly.

You're referring to smart linking. Indeed, smart linking should also be disabled (use -XS to force regular static linking)

Jonas

Reply by email

Guillermo Martínez Jiménez

2009/2/21 Jonas Maebe

Show quoted text 8 lines
On 21 Feb 2009, at 19:35, Guillermo Martínez Jiménez wrote: > I've tried your suggestion about the symbol stripping and had the same > result. Did you also disable smart linking? (-XX-)

I didn't.

Is there more things I can disable and test? *_*

Reply by email

Jonas Maebe
to Guillermo Martínez Jiménez
Guillermo Martínez Jiménez wrote 11 lines
2009/2/21 Jonas Maebe > > On 21 Feb 2009, at 19:35, Guillermo Martínez Jiménez wrote: > >> I've tried your suggestion about the symbol stripping and had the >> same >> result. > > Did you also disable smart linking? (-XX-) I didn't.

Sorry, the above is wrong. I meant -XS (in combination with -Xs-). - XX- will not disable smart linking.

Is there more things I can disable and test? *_*

Nothing comes to mind.

Jonas

Reply by email