Issue with Static Libraries

Hello World;
I believe I’m having an issue with static libraries of SDL. I have a
sample source that I have compiled and linked using shared libraries.
Created the respective executable, ran it and it worked fine. Figured if I
link it with a static version of the library, it would work too. But to my
amazement, it didn’t.
Any reason for this?

Thanks in advance.

Hello World;
I believe I’m having an issue with static libraries of SDL. I have a
sample source that I have compiled and linked using shared libraries.
Created the respective executable, ran it and it worked fine. Figured if I
link it with a static version of the library, it would work too. But to my
amazement, it didn’t.

Not that I can think of. Can you describe how it’s not working? Is there
an error message?

See ya,
-Sam Lantinga, Founder and President, Galaxy Gameworks LLC

Mike Mike wrote:

Hello World;
I believe I’m having an issue with static libraries of SDL. I have a
sample source that I have compiled and linked using shared libraries.
Created the respective executable, ran it and it worked fine. Figured if I
link it with a static version of the library, it would work too. But to my
amazement, it didn’t.
Any reason for this?

You did not specify what exactly did not work, but a possible explanation
is as follows: When you link with a dynamic library then this library
may call other libraries, whereas this is not possible in case of a static
library. I am not shure whether this is valid for all platforms however.

Wouter Boeke

W.Boeke wrote:

Mike Mike wrote:

Hello World;
I believe I’m having an issue with static libraries of SDL. I have a
sample source that I have compiled and linked using shared libraries.
Created the respective executable, ran it and it worked fine. Figured
if I
link it with a static version of the library, it would work too. But
to my
amazement, it didn’t.
Any reason for this?

You did not specify what exactly did not work, but a possible explanation
is as follows: When you link with a dynamic library then this library
may call other libraries, whereas this is not possible in case of a
static
library. I am not shure whether this is valid for all platforms however.

A static library can make calls to dynamic libraries, at least on Linux.

In one of my projects I did exactly that. I think I did it initially
just to see if it could be done, I have no real reason for doing so.

The only thing I found is on Ubuntu - I’m now using Debian and haven’t
tried, but they should all be the same - when linking 100% dynamically
if I left out a library it may have still compiled, linked and ran fine
(i.e. SDL_image, but not specifying -ljpeg -lpng, etc.) whereas when I
linked in my lib statically, I then needed to specify every library.

Oh yh,
When I tried to link it with the static library;

gcc fire.c -I /usr/local/include/SDL/ -L …/…/SDL-1.2.13/build/.libs/
-lSDL -o tesyn

I got error messages stating the following;

…/…/SDL-1.2.13/build/.libs//libSDL.a(SDL_systhread.o): In function
SDL_SYS_WaitThread': /home/Michael/project/SDL-1.2.13/./src/thread/pthread/SDL_systhread.c:107: undefined reference topthread_join’
…/…/SDL-1.2.13/build/.libs//libSDL.a(SDL_systhread.o): In function
SDL_SYS_SetupThread': /home/Michael/project/SDL-1.2.13/./src/thread/pthread/SDL_systhread.c:89: undefined reference topthread_sigmask’
…/…/SDL-1.2.13/build/.libs//libSDL.a(SDL_systhread.o): In function
SDL_SYS_CreateThread': /home/Michael/project/SDL-1.2.13/./src/thread/pthread/SDL_systhread.c:64: undefined reference topthread_create’
…/…/SDL-1.2.13/build/.libs//libSDL.a(SDL_systhread.o): In function
SDL_SYS_KillThread': /home/Michael/project/SDL-1.2.13/./src/thread/pthread/SDL_systhread.c:113: undefined reference topthread_cancel’
…/…/SDL-1.2.13/build/.libs//libSDL.a(SDL_syssem.o): In function
SDL_SemPost': /home/Michael/project/SDL-1.2.13/./src/thread/pthread/SDL_syssem.c:149: undefined reference tosem_post’
…/…/SDL-1.2.13/build/.libs//libSDL.a(SDL_syssem.o): In function
SDL_SemValue': /home/Michael/project/SDL-1.2.13/./src/thread/pthread/SDL_syssem.c:132: undefined reference tosem_getvalue’
…/…/SDL-1.2.13/build/.libs//libSDL.a(SDL_syssem.o): In function
SDL_SemWait': /home/Michael/project/SDL-1.2.13/./src/thread/pthread/SDL_syssem.c:90: undefined reference tosem_wait’
…/…/SDL-1.2.13/build/.libs//libSDL.a(SDL_syssem.o): In function
SDL_SemTryWait': /home/Michael/project/SDL-1.2.13/./src/thread/pthread/SDL_syssem.c:75: undefined reference tosem_trywait’
…/…/SDL-1.2.13/build/.libs//libSDL.a(SDL_syssem.o): In function
SDL_DestroySemaphore': /home/Michael/project/SDL-1.2.13/./src/thread/pthread/SDL_syssem.c:61: undefined reference tosem_destroy’
…/…/SDL-1.2.13/build/.libs//libSDL.a(SDL_syssem.o): In function
SDL_CreateSemaphore': /home/Michael/project/SDL-1.2.13/./src/thread/pthread/SDL_syssem.c:47: undefined reference tosem_init’
…/…/SDL-1.2.13/build/.libs//libSDL.a(SDL_sysmutex.o): In function
SDL_CreateMutex': /home/Michael/project/SDL-1.2.13/./src/thread/pthread/SDL_sysmutex.c:49: undefined reference topthread_mutexattr_init’
/home/Michael/project/SDL-1.2.13/./src/thread/pthread/SDL_sysmutex.c:51:
undefined reference to pthread_mutexattr_settype' ../../SDL-1.2.13/build/.libs//libSDL.a(SDL_gamma.o): In functionCalculateGammaFromRamp’:
/home/Michael/project/SDL-1.2.13/./src/video/SDL_gamma.c:84: undefined
reference to log' /home/Michael/project/SDL-1.2.13/./src/video/SDL_gamma.c:84: undefined reference tolog’
…/…/SDL-1.2.13/build/.libs//libSDL.a(SDL_gamma.o): In function
CalculateGammaRamp': /home/Michael/project/SDL-1.2.13/./src/video/SDL_gamma.c:63: undefined reference topow’
…/…/SDL-1.2.13/build/.libs//libSDL.a(SDL_x11gl.o): In function
X11_GL_UnloadLibrary': /home/Michael/project/SDL-1.2.13/./src/video/x11/SDL_x11gl.c:450: undefined reference todlclose’
…/…/SDL-1.2.13/build/.libs//libSDL.a(SDL_x11gl.o): In function
X11_GL_LoadLibrary': /home/Michael/project/SDL-1.2.13/./src/video/x11/SDL_x11gl.c:487: undefined reference todlopen’
/home/Michael/project/SDL-1.2.13/./src/video/x11/SDL_x11gl.c:501: undefined
reference to dlsym' /home/Michael/project/SDL-1.2.13/./src/video/x11/SDL_x11gl.c:503: undefined reference todlsym’
/home/Michael/project/SDL-1.2.13/./src/video/x11/SDL_x11gl.c:505: undefined
reference to dlsym' /home/Michael/project/SDL-1.2.13/./src/video/x11/SDL_x11gl.c:507: undefined reference todlsym’
/home/Michael/project/SDL-1.2.13/./src/video/x11/SDL_x11gl.c:509: undefined
reference to dlsym' ../../SDL-1.2.13/build/.libs//libSDL.a(SDL_x11gl.o):/home/Michael/project/SDL-1.2.13/./src/video/x11/SDL_x11gl.c:511: more undefined references todlsym’ follow
…/…/SDL-1.2.13/build/.libs//libSDL.a(SDL_sysloadso.o): In function
SDL_LoadFunction': /home/Michael/project/SDL-1.2.13/./src/loadso/dlopen/SDL_sysloadso.c:56: undefined reference todlerror’
…/…/SDL-1.2.13/build/.libs//libSDL.a(SDL_sysloadso.o): In function
SDL_LoadObject': /home/Michael/project/SDL-1.2.13/./src/loadso/dlopen/SDL_sysloadso.c:36: undefined reference todlopen’
/home/Michael/project/SDL-1.2.13/./src/loadso/dlopen/SDL_sysloadso.c:37:
undefined reference to dlerror' ../../SDL-1.2.13/build/.libs//libSDL.a(SDL_sysloadso.o): In functionSDL_UnloadObject’:
/home/Michael/project/SDL-1.2.13/./src/loadso/dlopen/SDL_sysloadso.c:65:
undefined reference to `dlclose’
collect2: ld returned 1 exit status

Now, based on the above, I noticed it was complaining about the following;
-ldl (which I thought was only meant to be called when making use of
dynamic libraries)
-lpthread

Ok, I included them, using;

gcc fire.c -I /usr/local/include/SDL/ -L …/…/SDL-1.2.13/build/.libs/ -lSDL
-ldl -lpthread -o tesyn

which also gave errors (below)

…/…/SDL-1.2.13/build/.libs//libSDL.a(SDL_gamma.o): In function
CalculateGammaFromRamp': /home/Michael/project/SDL-1.2.13/./src/video/SDL_gamma.c:84: undefined reference tolog’
/home/Michael/project/SDL-1.2.13/./src/video/SDL_gamma.c:84: undefined
reference to log' ../../SDL-1.2.13/build/.libs//libSDL.a(SDL_gamma.o): In functionCalculateGammaRamp’:
/home/Michael/project/SDL-1.2.13/./src/video/SDL_gamma.c:63: undefined
reference to `pow’
collect2: ld returned 1 exit status

Now, at this point I didn’t know what to do.

Any ideas?

Thanks in advance.

MichaelOn Sun, Mar 22, 2009 at 10:37 AM, Mike Mike <@Mike_Mike> wrote:

Hello World;
I believe I’m having an issue with static libraries of SDL. I have a
sample source that I have compiled and linked using shared libraries.
Created the respective executable, ran it and it worked fine. Figured if I
link it with a static version of the library, it would work too. But to my
amazement, it didn’t.
Any reason for this?

Thanks in advance.

Figured, I should also add that configuring SDL to make static libraries
alone, creates only one library (libSDL.a)

Thought I say.

Thanks

log? pow? Did you try -lm?

Jonny D

2009/3/25 Mike Mike > Figured, I should also add that configuring SDL to make static libraries

alone, creates only one library (libSDL.a)

Thought I say.

Thanks


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hiyya, this thing is causing you too much pain. I’d try it on a seperate machine or on a different compiler. I would use one where there are setup instructions on the sdl website if u can.-----------------------------------------------

---- Mike Mike wrote:

=============
Oh yh,
When I tried to link it with the static library;

gcc fire.c -I /usr/local/include/SDL/ -L …/…/SDL-1.2.13/build/.libs/
-lSDL -o tesyn

I got error messages stating the following;

…/…/SDL-1.2.13/build/.libs//libSDL.a(SDL_systhread.o): In function
SDL_SYS_WaitThread': /home/Michael/project/SDL-1.2.13/./src/thread/pthread/SDL_systhread.c:107: undefined reference topthread_join’
…/…/SDL-1.2.13/build/.libs//libSDL.a(SDL_systhread.o): In function
SDL_SYS_SetupThread': /home/Michael/project/SDL-1.2.13/./src/thread/pthread/SDL_systhread.c:89: undefined reference topthread_sigmask’
ect ect ect

Cheers Guys,
That worked like a charm. I.e. including the ‘lm’ library.

But what does this mean for me?
I did all this to know if it’s possible (using the gcc compiler as
reference).

Now, I plan to replicate the same thing using a different compiler
(cross-compiler = sparc-linux-gcc).

I have the cross-compiled version of SDL. Both shared and Static.

The question now is, do you think I would need the other libraries (lm
lpthread & ldl) ?

I did a test using the cross-compiler to compile and link he source. It
compiled, linked and created the executable successfully using only just
lSDL and lpthread (neglecting ldl and lm)

(Now, if this would work or if it’s is right, I don’t know. It’s probably
wrong but not giving out errors).

Thanks in advance

Michael

2009/3/25 Mike Mike :

? But what does this mean for me?
?I did all this to know if it’s possible (using the gcc compiler as
reference).

Running “sdl-config --static-libs” should have told you all of those
libraries to use, no?

Now, I plan to replicate the same thing using a different compiler
(cross-compiler = sparc-linux-gcc).

I have the cross-compiled version of SDL. Both shared and Static.

The question now is, do you think I would need the other libraries (lm
lpthread & ldl) ?

You’ll need cross-compiled versions of those too (or copying them from
the target system is a common way out). Both of these should normally
be part of the base system (containing heavily platform-dependent
code), or be integrated in libc itself (if that’s the case, that might
be why it did compile).

Producing .o files or static libraries with a cross-compiler is
generally not that hard, since you just need your code and the
appropriate compiler, but when linking executables or shared
libraries, it gets hairier, because you start needing the libraries
for that platform.

I recently had a minor version of that problem, where I was trying to
compile a 32 bit binary on a 64 bit system (x86), and while gcc had no
problem restricting itself to a Pentium III instruction set and
outputting 32 bit object files, my userspace was all 64 bit, so I had
no libraries available to link the final binary. Copying a bunch of 32
bit (or, in your case, Linux/SPARC) libraries from another system into
a directory, and sticking a -L flag pointing to that directory can
simply do the trick. The cross-compiler setup usually has a directory
all picked out, with the name of the target in it, something like
/usr/lib/gcc/sparc-linux-gcc/4.2.2. Running "locate sparc-linux-gcc"
might be helpful in finding that directory (or you can just use -L).–
http://pphaneuf.livejournal.com/