PDA

View Full Version : Linking with Linux .so files



Ñuño Martínez
15-12-2006, 11:11 PM
Hello everybody.

I'm new in this forum but I was coding games in C with Allegro for a long time, but since the TINS'06 competition (http://amarillion.bafsoft.net/tins06/) where I wrote my entry in Pascal (Train (http://amarillion.bafsoft.net/tins06/review.php?gameid=38&show=1)) I decided to use only Pascal to create games.

So I decided to write a wrapper to use Allegro in Pascal, and I success in Windows 8) but now I'm trying to port it to Linux and it doesn't work. It says it can't find the library files (-lalleg). All the files it needs are in /usr/local/lib and theirs names are liballeg_unsharable.a, liballeg.so.4.2 (this is a link to the real shared object) and alpas42.so (I wrote this one to allow Delphi-lovers to use it :toocool: ).

I'm using next code to link the files:


(**** from albase.pas ****)
INTERFACE

CONST
{ Access to the dynamic modules. }
{$IFDEF WIN32}
ALLEGRO_SHARED_LIBRARY_NAME = 'alleg42.dll';
ALL_PAS_SHARED_LIBRARY_NAME = 'alpas42.dll';
{$ENDIF}
{$IFDEF UNIX}
ALLEGRO_SHARED_LIBRARY_NAME = 'liballeg.so.4.2';
ALL_PAS_SHARED_LIBRARY_NAME = 'alpas42.so';
{$LINKLIB alleg_unsharable}
{$ENDIF}


And the next to declare a procedure:


(**** from aldraw.pas ****)
INTERFACE

USES
albase, albitmap; { Needs some basic definitions. }

(* Clipping. *)
PROCEDURE al_set_clip_rect (bmp: AL_BITMAPptr; x1, y1, x2, y2: AL_INT); CDECL;
EXTERNAL ALLEGRO_SHARED_LIBRARY_NAME NAME 'set_clip_rect';


And to build the examples (using GNU/makefile):



(**** from makefile.all ****)
# Executables.
$(EXMDIR)/%$(BINSUF): $(EXMDIR)/%.dpr
fpc -Fu$&#40;LIBDIR&#41; FE$&#40;EXMDIR&#41; -FU$&#40;LIBDIR&#41; -WG+ $< -o$@


As I've said, it compiles, links and runs perfectly in Windows XP but it doesn't in Linux.

I'm using Free Pascal version 2.0.2 and GCC 4.0.3 in an actualized Kubuntu (no Lazarus) in a IBM ThinkCentre (P4, 512Mb blah blah...).

The Windows XP is in the same computer (other partition) with same compilers and also using MinGW32 5.1 and Msys 1.0.

Can anybody help me?

[comment] I know, there are a lot of great libraries for Free Pascal to make great games, but I like Allegro and I'll still using it. Please, do not try to convince me.

Almindor
16-12-2006, 10:49 AM
What exactly doesn't work? Does it compile in linux? Does it link? if not, what errors do you get?

technomage
16-12-2006, 11:42 AM
I think you need to link to the .so directly. I had to do this when interfacing with mysql I had to add

-Fl/usr/local/lib/mysql

as a compiler option.

perhaps you need to do the same here :?:

FPK
16-12-2006, 01:59 PM
I guess you've to install the allegro development package.

Ñuño Martínez
16-12-2006, 09:22 PM
What exactly doesn't work? Does it compile in linux? Does it ]
It compiles but doesn't link. It says "ld: Can't find -lalleg".
[quote="technomage"]I think you need to ]
:doh: I'll try it. Thanks for the suggestion, but today was a bussy day and I need to rest.
[quote="FPK"]I guess you've to install the allegro development package.
I did it, but thanks for remember me this. Some years ago I forgot to install the development package of a library and it was too embarrasing :oops:

savage
17-12-2006, 11:36 AM
Make sure that the shared object is accessible from your login, so it may be a rights/security issue.

Ñuño Martínez
17-12-2006, 07:15 PM
I've tried the -Fl option but it doesn't work. I think I should learn more about the way Linux uses the .so files. I'll finish with the documentation and then release it; may be somebody who has more experience can fix it. Until then, I can use it in Win32.

sekelsenmat
24-12-2006, 04:10 PM
Why don´t you use the Allegro bindings for pascal

http://allegro-pas.sourceforge.net/

Ñuño Martínez
27-12-2006, 10:43 AM
Great! Somebody suggest Allegro.pas to somebody! This is the happyest day of my life! :D
But there's a problem...


A wrapper to use the Allegro library with Pascal compilers
by ?ëu?±o Mart??nez, December,2006.

I'm "that" ?ëu?±o Mart??nez. Anyway, thanks for the try. ;)

Almindor
29-12-2006, 10:25 AM
Make sure it's the right name you use. Also -lname must match for ld. Basicly check out what the filename of allegro so file is, if the symlink to name.so.#.#.# is there and is right, and if it accepts -lallegro

You can test alot with gcc to see what that uses. (btw you have to explicitly tell this to gcc, so if it works with -lallegro in gcc and not via fp {don't forget, both use ld as linker} it's odd)

Legolas
04-01-2007, 04:33 PM
Try to omit linking stage (fpc -s yourfile.pas) and open link.res, so you can check if paths are correct and if the lib is passed to the linker with the exact name

Ñuño Martínez
04-01-2007, 08:36 PM
[quote="Almindor"]Make sure it's the right name you use. Also -lname must match for ld. Basicly check out what the filename of allegro so file is, if the sym]

The soname is "liballeg.so.4.2", which is the same I'm using in the "EXTERNAL" declaration. The real name of the library is "liballeg-4.2.1.so" so I should pass to the linker "-lalleg-4.2.1", don't I?

The files and the symlink are right:

% ls -l /usr/local/lib
total xxx
drwxr-xr-x 3 root root 4096 2006-12-15 21&#58;01 allegro
-rwxr-xr-x 1 root root 165105 2006-12-15 22&#58;01 alpas42.so
drwxr-xr-x 4 root root 4096 2005-12-07 10&#58;08 fpc
-rwxr-xr-x 1 root root 898213 2006-12-15 21&#58;01 liballeg-4.2.1.so
lrwxrwxrwx 1 root root 17 2006-12-15 21&#58;01 liballeg.so.4.2 -> liballeg-4.2.1.so
-rw-r--r-- 1 root root 176444 2006-12-15 21&#58;01 liballeg_unsharable.a


[quote="Almindor"]You can test alot with gcc to see what that uses. (btw you have to explicitly tell this to gcc, so if it works with -lallegro in gcc and not via fp {don't forget, both use ld as ]

In gcc uses an script that returns all options it needs:


% allegro-config --libs
-L/usr/local/lib -L/usr/X11R6/lib -Wl,--export-dynamic -lalleg-4.2.1 -lalleg_unsharable


[quote="Legolas"]Try to omit ]

Done. I used:
fpc -s -Fulib -FEexamples -FUlib -WG+ examples/extruec.dpr -oexamples/extruec.bin


The paths are correct but the libnames aren't correct. This is the actual content of link.res:

INPUT&#40;
-lalleg
-lalpas42
-lalleg_unsharable
&#41;


And this is what (I think) it shoul be:


INPUT&#40;
-lalleg-4.2.1
-lalpas42
-lalleg_unsharable
&#41;


[edit] Wait, I've find that there are a "SEARCH_DIR(/usr/lib/)" but there are not a "SEARCH_DIR(/usr/local/lib/)". Is this the problem? How can I fix it?

[edit] Surelly I'm the most stupid man here: technomage said how to fix it. Anyway it still not linking...


% make examples
fpc -Fulib -FEexamples -FUlib -Fl/usr/local/lib -WG+ examples/exdata.dpr -oexamples/exdata.bin
Free Pascal Compiler version 2.0.2 &#91;2005/12/07&#93; for i386
Copyright &#40;c&#41; 1993-2005 by Florian Klaempfl
Target OS&#58; Linux for i386
Compiling examples/exdata.dpr
Linking examples/exdata.bin
/usr/bin/ld&#58; no se puede encontrar -lalleg
exdata.dpr&#40;106,1&#41; Error&#58; Error while linking
Error&#58; /usr/local/bin/ppc386 returned an error exitcode &#40;normal if you did not specify a source file to be compiled&#41;
make&#58; *** &#91;examples/exdata.bin&#93; Error 1

The link.res file is the same but added a SEARCH_DIR(/usr/local/lib/)" line.

grudzio
04-01-2007, 10:43 PM
How about creating a symbolic link to the library in the /usr/lib/ directory?
It worked for me when I could not link to the glu library.

Or maybe it is enough to run ldconfig?

You could also look at sdl.pas in JEDI_SDL to see how it is done there.

marcov
10-04-2007, 11:58 AM
[quote="Almindor"]Make sure it's the right name you use. Also -lname must match for ld. Basicly check out what the filename of allegro so file is, if the sym]

The soname is "liballeg.so.4.2", which is the same I'm using in the "EXTERNAL" declaration. The real name of the library is "liballeg-4.2.1.so" so I should pass to the linker "-lalleg-4.2.1", don't I?


No I think external strips it. As you can seen in the error msg.

[quote]
The files and the symlink are right:

% ls -l /usr/local/lib
total xxx
drwxr-xr-x 3 root root 4096 2006-12-15 21&#58;01 allegro
-rwxr-xr-x 1 root root 165105 2006-12-15 22&#58;01 alpas42.so
drwxr-xr-x 4 root root 4096 2005-12-07 10&#58;08 fpc
-rwxr-xr-x 1 root root 898213 2006-12-15 21&#58;01 liballeg-4.2.1.so
lrwxrwxrwx 1 root root 17 2006-12-15 21&#58;01 liballeg.so.4.2 -> liballeg-4.2.1.so
-rw-r--r-- 1 root root 176444 2006-12-15 21&#58;01 liballeg_unsharable.a


create liballeg.so > liballeg-4.2.1.so and you'll see it links.

If you have 2.0.4+, and are not the faint of heart kind, you might want to experiment with the undocumented -XL switches. See paragraph 5.2 in

http://www.stack.nl/~marcov/buildfaq.pdf

Ñuño Martínez
11-04-2007, 02:22 PM
Hello. Sorry but I was out of business for a long time. And I'll be there for some weeks more... :(

I can't to use my computer now but I want to make few comments.

How about creating a symbolic ]
It should be enough to run ldconfig. By the way, all my old Allegro C games compiled and runs without problems, so I think this isn't the problem.

I've seen how JEDI-SDL does it and I think it's too similar than I did. Thanks anyway. :)

[quote="?ëu?±o Mart??nez"][quote="Almindor"]Make sure it's the right name you use. Also -lname must match for ld. Basicly check out what the filename of allegro so file is, if the sym]

The soname is "liballeg.so.4.2", which is the same I'm using in the "EXTERNAL" declaration. The real name of the library is "liballeg-4.2.1.so" so I should pass to the linker "-lalleg-4.2.1", don't I?


No I think external strips it. As you can seen in the error msg.
I see, but why?


create liballeg.so > liballeg-4.2.1.so and you'll see it ]
Did you test it? I you did it and it worked then all my problems with Allegro.pas are gone! :D

[quote="marcov"]If you have 2.0.4+, and are not the faint of heart kind, you might want to experiment with the undocumented -XL switches. See paragraph 5.2 in

http://www.stack.nl/~marcov/buildfaq.pdf
I'm not sure what "are not the faint of heart kind" means :?

By the way, I've read the PDF and I'll test it as soon as I can (hopefully May 1st, but no before that).

A last report: I released the latest version of Allegro.pas in February 1st. If you did test the previous version (December 17th) please download the project package (http://sourceforge.net/project/showfiles.php?group_id=184664) again.

Thanks.