PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

Linker option

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
zzzhong



Joined: 23 Dec 2004
Posts: 2

PostPosted: Mon Feb 21, 2005 9:45 am    Post subject: Linker option Reply with quote

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

Code:

[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,liblam.so.0 \
-o .libs/liblam.so.0.0.0


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:

Code:

/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/ld-linux-x86-64.so.2 \
../../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/liblam.so.0.0.0 \
-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 liblam.so.0 \
-lc -lnspgc -lpgc -lm -lgcc -lc -lgcc \
/usr/lib/gcc-lib/x86_64-redhat-linux/3.2.3/crtendS.o \
/usr/lib64/crtn.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.
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6134
Location: The Portland Group Inc.

PostPosted: Mon Feb 21, 2005 12:41 pm    Post subject: Reply with quote

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.

Example:

Code:
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,liblam.so.0 -o .libs/liblam.so.0.0.0


- Mat
Back to top
View user's profile
zzzhong



Joined: 23 Dec 2004
Posts: 2

PostPosted: Tue Feb 22, 2005 11:18 am    Post subject: Reply with quote

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?
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6134
Location: The Portland Group Inc.

PostPosted: Tue Feb 22, 2005 12:39 pm    Post subject: Reply with quote

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
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group