tags:

views:

42

answers:

1

Hello,

Note: Despite the mentioning of Python in the following there is a good chance for my problem not to be Python related at all. If I am not mistaken the “module” I mention is equivalent to a C library—at least for the concerns of my problem.

On Debian I am trying to create a Python module with C, which in turn uses the GSL. The following Makefile successfully compiles it:

CC = gcc -Wall -fPIC -O3
NAME = meinzeug

matrizenwuerfler: $(SRC)
$(CC) -o $(NAME).o -I/usr/lib/python2.5/site-packages/numpy/core/include -I/usr/include/python2.5 -c $(NAME).c
$(CC) -shared -o $(NAME).so -lgsl -lgslcblas -lm $(NAME).o

Because this module is supposed to be used by (Linux) machines other than mine, I want the GSL to be included into the module (or be shipped with it).

However, if I add -static as option to the last line of the Makefile, I get the following error:

gcc -Wall -fPIC -O3 -shared -static -o meinzeug.so -lgsl -lgslcblas -lm meinzeug.o
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.3.2/crtbeginT.o: relocation R_X86_64_32 against `__DTOR_END__' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/4.3.2/crtbeginT.o: could not read symbols: Bad value
collect2: ld returned 1 exit status

Adding -Wl,-Bstatic before the library linking results in a different error:

gcc -Wall -fPIC -O3 -shared -o meinzeug.so -Wl,-Bstatic -lgsl -lgslcblas -lm meinzeug.o
/usr/bin/ld: cannot find -lgcc_s
collect2: ld returned 1 exit status

Other Stuff, that did not work: Recompiling GSL with fPIC, -static-libgcc, permutating the options. What I did not try yet, is compiling gcc with fPIC or similar.

+2  A: 

Try

gcc -Wall -fPIC -O3 -shared -o meinzeug.so /usr/lib/libgsl.a -lm meinzeug.

as you cannot do

gcc -Wall -fPIC -O3 -shared -static ...   # shared and static at the same time ?

so you would provide the static library of GSL alongside with your code.

At the end of the day, I would punt and keep the dependency on the GSL. Just about everybody has it, and the API is pretty stable.

Dirk Eddelbuettel
The first suggestion does not work — the program exits with undefined symbol: gsl_rng_taus which is the same as if I had not linked GSL at all. What I do not understand is, why `-static` and `-shared` are contradictory. In my understanding `-static` avoids, that other libraries are linked into my library dynamically, while `-shared` enables my library to be linked dynamically in turn. In case I count on GSL being available on other systems, could there be version or location incompitibilities?
Wrzlprmft
Just checking here: you do have a file /usr/lib/libgsl.a ?
Dirk Eddelbuettel
Yes, even copied it to the program’s folder in hope that it might help.
Wrzlprmft