error when compiling the program to get a shared library

Hello,

When I compile my pgf90 program to get outputfile as a shared library, I meet following error:

/usr/bin/ld: toolkit.o: relocation R_X86_64_32S against `a local symbol’ can not be used when making a shared object; recompile with -fPIC
toolkit.o: could not read symbols: Bad value

My own compiling command is :

/usr/local/pgi/linux86-64/6.1/bin/pgf90 -shared -fPIC *.o
-L/usr/local/lib64 -lnetcdf
-L/usr/lib64
-L/usr/local/pgi/linux86-64/6.1/libso
-o $output_file

I am using the 6.1 64bit version on a AMD system.

Thanks lots.

No, that’s your link command. You need to compile the source files to .o with -Kpic (or -fpic, PGI seems to accept most common variants).

e.g. you have toolkit.f90:
pgf90 -c -Kpic -otoolkit.o toolkit.f90

Then

pgf90 -shared -fPIC *.o -L/usr/local/lib64 -lnetcdf -L/usr/lib64 -L/usr/local/pgi/linux86-64/6.1/libso
-o $output_file

Thanks the reply. Now the new problem is that:

/usr/bin/ld: /usr/local/lib64/libnetcdf.a(fort-v2compat.o): relocation R_X86_64_32S against `a local symbol’ can not be used when making a shared object; recompile with -fPIC
/usr/local/lib64/libnetcdf.a: could not read symbols: Bad value

I’m not sure whether this kind error comes from my codes or the linking command. If it comes from linking command, what should I do to solve it. My linking command is still the same as above.

Thanks for your time

Hi tingting,

You need to recompile NetCDF with “-fPIC” as well.

  • Mat