Dynamic libs and distributing program in linux
Kevin Epps

How would I build a program in linux to be able to dynamically link to libs in the parent folder for people that may not have allegro libs to begin with? So, if someone where to download a tar of all the files, libs included, needed for the program, they would be able to run it?

kazzmir

You can't. If you want to give people Allegro in case they dont have it then static link Allegro into your program.

Kevin Epps

ahh ok. So when I build, I need to use `allegro-config --static` -static, and make sure that 'liballeg.a' is inside the parent folder, right?

kazzmir

yea.. i think thats it. its probably explained better in the manual.

Peter Wang

You don't have to statically link. The way you do it is create a wrapper shell script that sets LD_LIBRARY_PATH (and perhaps other environment variables) before calling the real binary.

Kevin Epps

Ahh yeah. Great idea!

--EDIT
Question, which files would I include in the package if I take that route?

kazzmir
Quote:

You don't have to statically link. The way you do it is create a wrapper shell script that sets LD_LIBRARY_PATH (and perhaps other environment variables) before calling the real binary.

Whats the difference between that and static linking? If he distributes the allegro libraries and sets LD_LIBRARY_PATH to the directory with it then thats the same thing.

All you can do is say in the readme "its ok to erase the lib/ directory if you already have allegro" but they've already downloaded the game so who cares?

Kevin Epps

Hey Kazzmir, I may have to go Peter's route. I use fmod, and I can't figure out how to compile that statically. I do have one question, though. I tried to have a makefile call the export call and then open the game, but it doesn't actually call the export call. How can I create a script that does this. Do I need to create a RPM?

kazzmir

makefile's are for compiling code. Here is a shell script to set things up for you

#!/bin/sh
LD_LIBRARY_PATH=lib:$LD_LIBRARY_PATH ./mygame

assuming the libaries are in $cwd/lib.

Kevin Epps

Great!!!

It works perfectly! Thanks for your help, Kazz!

Peter Wang
Quote:

Whats the difference between that and static linking?

Not a lot, but the user can upgrade the Allegro library if he likes, or change to use the system-wide library instead.

Milan Mimica
Quote:

#!/bin/sh
LD_LIBRARY_PATH=lib:$LD_LIBRARY_PATH ./mygame

This won't work if you run from another dir. You need to put this line first:
cd "$(dirname $(tr '\0' '*' < /proc/$$/cmdline | cut -d'*' -f2))"

Kevin Epps

Great, that works as well. Thanks for all of your help!

Trent Gamblin

If you static link you don't need liballeg.a. Allegro will be compiled into your executable.

Kevin Epps
Quote:

If you static link you don't need liballeg.a.

I may have to go Peter's route. I use fmod, and I can't figure out how to compile that statically.

Trent Gamblin

You can compile Allegro statically and still use dynamic fmod/other libs.

Kevin Epps

Oh well, I've already done the deed now.

Michael Faerber

If you've already solved this, maybe somebody can answer my very similar question: how to solve this error?

// test.c
#include <allegro.h>

int main()
{
  allegro_init();
  return 0;
}

GCC said:

michi@tux ~ $ gcc test.c `allegro-config --libs --static` -static
/usr/lib/liballeg.a(umodules.o): In function `_unix_load_modules':
: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/liballeg.a(file.o): In function `canonicalize_filename':
: warning: Using 'getpwent' in statically linked applications requires at runtim e the shared libraries from the glibc version used for linking
/usr/lib/liballeg.a(file.o): In function `canonicalize_filename':
: warning: Using 'setpwent' in statically linked applications requires at runtim e the shared libraries from the glibc version used for linking
/usr/lib/liballeg.a(file.o): In function `canonicalize_filename':
: warning: Using 'endpwent' in statically linked applications requires at runtim e the shared libraries from the glibc version used for linking
/usr/lib/libX11.a(GetDflt.o): In function `GetHomeDir':
: warning: Using 'getpwnam_r' in statically linked applications requires at runt ime the shared libraries from the glibc version used for linking
/usr/lib/libX11.a(GetDflt.o): In function `GetHomeDir':
: warning: Using 'getpwuid_r' in statically linked applications requires at runt ime the shared libraries from the glibc version used for linking
/usr/lib/libX11.a(x11_trans.o): In function `_X11TransSocketOpen':
: warning: Using 'getaddrinfo' in statically linked applications requires at run time the shared libraries from the glibc version used for linking
/usr/lib/libX11.a(x11_trans.o): In function `_X11TransSocketUNIXConnect':
: warning: Using 'gethostbyname' in statically linked applications requires at r untime the shared libraries from the glibc version used for linking
/usr/lib/libX11.a(x11_trans.o): In function `_X11TransSocketINETConnect':
: warning: Using 'getservbyname' in statically linked applications requires at r untime the shared libraries from the glibc version used for linking
/usr/lib/libXcursor.a(cursor.o): In function `XcursorImageLoadCursor':
: undefined reference to `XRenderFindStandardFormat'
/usr/lib/libXcursor.a(cursor.o): In function `XcursorImageLoadCursor':
: undefined reference to `XRenderCreatePicture'
/usr/lib/libXcursor.a(cursor.o): In function `XcursorImageLoadCursor':
: undefined reference to `XRenderCreateCursor'
/usr/lib/libXcursor.a(cursor.o): In function `XcursorImageLoadCursor':
: undefined reference to `XRenderFreePicture'
/usr/lib/libXcursor.a(cursor.o): In function `XcursorImagesLoadCursor':
: undefined reference to `XFixesSetCursorName'
/usr/lib/libXcursor.a(cursor.o): In function `XcursorImagesLoadCursor':
: undefined reference to `XRenderCreateAnimCursor'
/usr/lib/libXcursor.a(display.o): In function `_XcursorGetDisplayInfo':
: undefined reference to `XRenderQueryExtension'
/usr/lib/libXcursor.a(display.o): In function `_XcursorGetDisplayInfo':
: undefined reference to `XRenderQueryVersion'
/usr/lib/libX11.a(ConnDis.o): In function `_X11TransConnectDisplay':
: undefined reference to `XauDisposeAuth'
/usr/lib/libX11.a(ConnDis.o): In function `_X11TransConnectDisplay':
: undefined reference to `XauGetBestAuthByAddr'
/usr/lib/libX11.a(ConnDis.o): In function `_X11TransConnectDisplay':
: undefined reference to `XdmcpWrap'

[EDIT]
Actually I have solved some errors now by using:

GCC said:

gcc test.c `allegro-config --static` -static -lXrender -lXau -lXdmcp
/usr/lib/liballeg.a(umodules.o): In function `_unix_load_modules':
: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/liballeg.a(file.o): In function `canonicalize_filename':
: warning: Using 'getpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/liballeg.a(file.o): In function `canonicalize_filename':
: warning: Using 'setpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/liballeg.a(file.o): In function `canonicalize_filename':
: warning: Using 'endpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libX11.a(GetDflt.o): In function `GetHomeDir':
: warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libX11.a(GetDflt.o): In function `GetHomeDir':
: warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libX11.a(x11_trans.o): In function `_X11TransSocketOpen':
: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libX11.a(x11_trans.o): In function `_X11TransSocketUNIXConnect':
: warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libX11.a(x11_trans.o): In function `_X11TransSocketINETConnect':
: warning: Using 'getservbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libXcursor.a(cursor.o): In function `XcursorImagesLoadCursor':
: undefined reference to `XFixesSetCursorName'

But there is still at least one critical error left!

Kevin Epps

Hey Michael,

I took out that last -static and it worked for me.

This is how I compiled it.

gcc test.c -o test_program `allegro-config --libs --static`

Milan Mimica
Quote:

/usr/lib/liballeg.a(umodules.o): In function `_unix_load_modules':
: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

Well, although you are statically linking, some drivers will be built as dynamically linked modules. You can distribute them and set ALLEGRO_MODULES env. variable as appropriate, or pass --enable-modules=no option to ./configure but then you might not be able to run your program where for example alsa is not present.

Evert
Quote:

If you static link you don't need liballeg.a.

liballeg.a is the thing the loader links to when you build your executable. You never need it at run time.

Trent Gamblin

I know, but Kevin Epps said:

Quote:

ahh ok. So when I build, I need to use `allegro-config --static` -static, and make sure that 'liballeg.a' is inside the parent folder, right?

Kevin Epps

Hey Trent,

I didn't know if that was true or not. I was just asking a question to confirm if that was true.

Evert
Quote:

I know, but Kevin Epps said:

Even then it's not true, because if Allegro is installed properly, the compiler will find liballeg.a anyway.

Michael Faerber

Don't care about the warnings yet, please look at the critical error:

Quote:

/usr/lib/libXcursor.a(cursor.o): In function `XcursorImagesLoadCursor':
: undefined reference to `XFixesSetCursorName'

How to get this right?

Milan Mimica

You need a package which provides libXfixes.so file. This is part of Xorg server, 6.9.0 or newer.

Michael Faerber

Thanks Milan, your answer brought me to the right track - it works now!

Quote:

Well, although you are statically linking, some drivers will be built as dynamically linked modules. You can distribute them and set ALLEGRO_MODULES env. variable as appropriate, or pass --enable-modules=no option to ./configure but then you might not be able to run your program where for example alsa is not present.

Hmmm ... are you sure there is no other way?

Because GCC doesn't complain only about Allegro, but also about X11!

GCC said:

michi@tux ~ $ gcc test.c `allegro-config --static` -static -lXrender -lXau -lXdmcp -lXfixes
/usr/lib/liballeg.a(umodules.o): In function `_unix_load_modules':
: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/liballeg.a(file.o): In function `canonicalize_filename':
: warning: Using 'getpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/liballeg.a(file.o): In function `canonicalize_filename':
: warning: Using 'setpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/liballeg.a(file.o): In function `canonicalize_filename':
: warning: Using 'endpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libX11.a(GetDflt.o): In function `GetHomeDir':
: warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libX11.a(GetDflt.o): In function `GetHomeDir':
: warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libX11.a(x11_trans.o): In function `_X11TransSocketOpen':
: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libX11.a(x11_trans.o): In function `_X11TransSocketUNIXConnect':
: warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libX11.a(x11_trans.o): In function `_X11TransSocketINETConnect':
: warning: Using 'getservbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

Milan Mimica

I think this warnings would go away if you link your programs statically to libc, or distribute your libc (libc.so.6 file) with the app.

Strange I never got such warnings though.

EDIT:
But you need to distribute allegro modules if you want them to be used.

Kitty Cat

GCC's -static attempts to statically link all libs into the program. Quite a bit of the time, this is unnecessarry and troublesome. Using --static with allegro-config will link in the staticlink Allegro libs, if you have them built, which should be enough for people to play.

Milan Mimica

+ you might allegro modules

Thread #589020. Printed from Allegro.cc