Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Dynamic libs and distributing program in linux

Credits go to kazzmir and Peter Wang for helping out!
This thread is locked; no one can reply to it. rss feed Print
 1   2 
Dynamic libs and distributing program in linux
Kevin Epps
Member #5,856
May 2005
avatar

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
Member #1,786
December 2001
avatar

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
Member #5,856
May 2005
avatar

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
Member #1,786
December 2001
avatar

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

Peter Wang
Member #23
April 2000

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
Member #5,856
May 2005
avatar

Ahh yeah. Great idea!

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

kazzmir
Member #1,786
December 2001
avatar

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
Member #5,856
May 2005
avatar

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
Member #1,786
December 2001
avatar

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
Member #5,856
May 2005
avatar

Great!!!

It works perfectly! Thanks for your help, Kazz!

Peter Wang
Member #23
April 2000

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
Member #3,877
September 2003
avatar

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
Member #5,856
May 2005
avatar

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

Trent Gamblin
Member #261
April 2000
avatar

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

Kevin Epps
Member #5,856
May 2005
avatar

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
Member #261
April 2000
avatar

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

Kevin Epps
Member #5,856
May 2005
avatar

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

Michael Faerber
Member #4,800
July 2004
avatar

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!

--
"The basic of informatics is Microsoft Office." - An informatics teacher in our school
"Do you know Linux?" "Linux? Isn't that something for visually impaired people?"

Kevin Epps
Member #5,856
May 2005
avatar

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
Member #3,877
September 2003
avatar

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
Member #794
November 2000
avatar

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
Member #261
April 2000
avatar

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
Member #5,856
May 2005
avatar

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
Member #794
November 2000
avatar

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
Member #4,800
July 2004
avatar

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?

--
"The basic of informatics is Microsoft Office." - An informatics teacher in our school
"Do you know Linux?" "Linux? Isn't that something for visually impaired people?"

 1   2 


Go to: