Linker option

The command below is generated by GNU libtool, to link several static .a files into one large .so shared library.

[shtang@precision liblam]$ pgcc -shared \ 
-Wl,--whole-archive \
../../share/args/.libs/liblamargs.a \
../../share/boot/.libs/liblamboot.a \
 ( some more useful libraries )
../../share/trillium/.libs/liblamtrillium.a \
../../share/tstdio/.libs/liblamtstdio.a \
-Wl,--no-whole-archive  -ldl -lpthread -lc \
-Wl,-soname -Wl, \
-o .libs/

However, it turns out that pgcc do not pass “-Wl,xxx” option in the correct position. The “–whole-archive” to linker (man ld) means that subsequent object file will be include in output archive, where as “–no-whole-archive” means subseqneut libraries (in this case, -ldl, -lpthread, etc) will only use to search for symbol but not exported.

Using “pgcc -#” to check the linker command:

/usr/bin/ld /usr/lib64/crti.o \
/usr/lib/gcc-lib/x86_64-redhat-linux/3.2.3/crtbeginS.o \
-m elf_x86_64 -dynamic-linker \
/lib64/ \
../../share/args/.libs/liblamargs.a \
../../share/boot/.libs/liblamboot.a \
  ( my useful libraries for export )
../../share/trillium/.libs/liblamtrillium.a \
../../share/tstdio/.libs/liblamtstdio.a \
-o .libs/ \
-L/usr/pgi/linux86-64/5.2/lib \
-L/usr/lib64 \
-L/usr/lib/gcc-lib/x86_64-redhat-linux/3.2.3 \
-rpath /usr/pgi/linux86-64/5.2/lib \
-shared --whole-archive --no-whole-archive \
-ldl -lpthread -lc -soname \
-lc -lnspgc -lpgc -lm -lgcc -lc -lgcc \
/usr/lib/gcc-lib/x86_64-redhat-linux/3.2.3/crtendS.o \

“–whole-archive” is put after all useful libraries! But it should be put before them.

Any way to tell pgcc to link the file in the way I want?

Thank you very much.

Hi zzzhong,

You need to add the particular libraries to the “-Wl,–whole-archive” link flag concatenated using commas. This will pass the entire line, as is, to the linker.


pgcc -shared -Wl,--whole-archive,../../share/args/.libs/liblamargs.a,../../share/boot/.libs/liblamboot.a,(some_more_useful_libraries),../../share/trillium/.libs/liblamtrillium.a,../../share/tstdio/.libs/liblamtstdio.a  -Wl,--no-whole-archive  -ldl -lpthread -lc -Wl,-soname -Wl, -o .libs/
  • Mat

In that way, all there is a “No files to process” error

If I add some “dummy” input file, and get “-#” display, the order seems corrected now. But the “dummy” file is pass to linker and cause some trouble.

Is there some elegent way to skip the “No file…” checking?

Hi zzzhong,

I’ve submitted TPR#3477 to our compiler engineers asking that position sensitive switches have their order preserved. It doesn’t help you right now, but I wanted you to know that we will work on getting this issue corrected.

As for the “No files…” error, there isn’t a good solution here. You can either link directly using the ‘ld’ comand line found by using “-dryrun” or create a dummy object. Granted the dummy object solution is ugly, having a static empty procedure would have no effect on your dynamic library, except for the one reference.

  • Mat