static/dynamic linker-problem

I'm experimenting with making libraries, and I want to make a static library. The library itself links with other shared libraries, such as opengl. Is it possible to make a static library that itself links with a shared library? The reason I ask is that when I try to compile a test-program which uses the library using the following command:

$(CC) -static src/test.c -L./lib -lmylib -o bin/test $(CFLAGS)

where CFLAGS = -lglut -lGL -lGLU -lGLEW -lm -std=c99

the linker says it can't find -lGL, which I have linked successfully to many times before. The library itself compiles fine. This is probably just a n00b-error, as I have never compiled a library before, but I've been stuck on this for some time.

EDIT: Ok, I fixed the build-issue by putting -shared in front of the non-static libraries, but now the executable itself segfaults with the following error from gdb:
Program received signal SIGSEGV, Segmentation fault.
0x800003e7 in __do_global_dtors_aux ()
, even if main contains no code except for return 0. Does anyone know what this error means?

Last edited on
Not sure, but my understanding of libraries is that they are collections of functions to be used when developing programs and so there would not be a main function in a library.

My understanding of a static library is that it is just a bunch of object files put together in an archive. The book I have here (beginning linux programming - wrox press) says to use ar to create a static library.

The example given

ar crv lib.a bill.o fred.o 

which creates a static library lib.a containing the object files bill.o fred.o

Last edited on
Topic archived. No new replies allowed.