Failed to create a shared library .so

I’ve been struggling with creation of .so from a simple C code containing Acceleration part. The software I work on uses a plugin approach, so I highly rely on shared library loading mechanism.

The builds were performed on Ubuntu 9.04 x64 with latest updates, using PGI 9.0.4.

====== test.c ======
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv) {
float a[1000];

#pragma acc region
for (int i = 0; i < 1000; i++) {
a _= i+2;
return (EXIT_SUCCESS);

pgcc -shared -o -ta=nvidia -Minfo test.c

Compilation went fine, the block has been accelerated, kernel created successfully, but on the link time I’ve got an error:

tester@ubuntu:~/work/test$ pgcc -shared -ta=nvidia -Minfo -o empty.c
17, Generating copyout(a[0:999])
19, Loop is parallelizable
Accelerator kernel generated
19, #pragma for parallel, vector(256)
/usr/bin/ld: /opt/pgi/linux86-64/9.0-4/lib/libacc1.a(nvalloc.o): relocation R_X86_64_32S against `a local symbol’ can not be used when making a shared object; recompile with -fPIC
/opt/pgi/linux86-64/9.0-4/lib/libacc1.a: could not read symbols: Bad value

There’s no error when I produce an executable from the same code.

pgcc -o sample -ta=nvidia -Minfo test.c

I’ve tried a number of different ways: introduced -fpic (-fPIC), tried -mcmodel=small or mcmodel=medium, tried explicit linking with libacc1.a and the other static libs (libacc1.a is the only library containing the need CUDA methods). Nothing helped.

At the very moment I use a workaround: compile a static library, which is then linked inside my main executable together with libacc1.a and other necessary static libs. Not what I need, but at least this works.


  1. Is it by design that it is not possible to create shared libraries with an acceleration code inside? (hopefully not)
  2. What would be the way out? Can you please recompile libacc1.a with -fPIC as it is suggested (the best solution for me)? Can you alternatively produce, so the linker will be happy to live with it?
  3. any other working solution will be greatly appreciated.

    Thank you for your help and a very great product!

    kind regards

Hi Dimitri,

We should have “-fpic” compiled pgacc libraries (located under the libso directory) available with the upcoming 10.0 release.


Hi Mat,

thank you for the clarification. Looking forward the coming release!

kind regards

Sorry to say, but I still have this error with Linux x64 PGI Workstation 10.0.
I’m on Ubuntu 9.10, x64.

Explicit linking of gcc with any of the static libraries libacc1*.a give an error with about the same complaint. These libraries are the only one containing acc_init() symbol, thus one of them must be used.

<… compiling .o files - everything is fine… >

pgcc -ta=nvidia -noswitcherror -shared -o dist/Linux/PGI-Linux-x86/ -fPIC build/Linux/PGI-Linux-x86/forces.o build/Linux/PGI-Linux-x86/shiftCells.o
/usr/bin/ld: /opt/pgi/linux86-64/10.0/lib/libacc1.a(nvalloc.o): relocation R_X86_64_32S against `.rodata’ can not be used when making a shared object; recompile with -fPIC
/opt/pgi/linux86-64/10.0/lib/libacc1.a: could not read symbols: Bad value

Thank you for your help.


Hi Dimitri,

Sorry about that. Our engineer’s ran into some issue that prevented the inclusion of -fpic compiled versions of these libraries with 10.0. They are working on it, though.

I’ll update this post once I see that they are there. You can also send a note to and ask to be added the notification list for TPR#16251.

  • Mat