Bugzilla – Bug 149351
Can't link /usr/lib64/libnetcdf.a into a shared library
Last modified: 2006-02-09 09:23:46 UTC
Hi, I have package netcdf-3.6.0-4 installed on my x86_64 system. I'm trying to build a test.so shared object with: > gcc -fPIC -c test.c -o test.o > gcc -shared -o test.so test.o /usr/lib64/libnetcdf.a /usr/lib64/gcc/x86_64-suse-linux/4.0.2/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/libnetcdf.a(error.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC /usr/lib64/libnetcdf.a: could not read symbols: Bad value collect2: ld returned 1 exit status It looks like /usr/lib64/libnetcdf.a has not been compiled with -fPIC option. > uname -a Linux gladstone 2.6.13-15.7-smp #1 SMP Tue Nov 29 14:32:29 UTC 2005 x86_64 x86_64 x86_64 GNU/Linux > gcc --version gcc (GCC) 4.0.2 20050901 (prerelease) (SUSE Linux) > ld --version GNU ld version 2.16.91.0.2 20050720 (SuSE Linux) My test.c file contains: #include <stdio.h> #include <string.h> #include <netcdf.h> void test(const int *ncerr, const int *len, char *errortext[]) { strncpy(errortext[0], nc_strerror(*ncerr), *len); } H.
This is correct, you cannot in general link a static library into a static one. And static libraries are not compiled with -fPIC.