|
| View previous topic :: View next topic |
| Author |
Message |
zzzhong
Joined: 23 Dec 2004 Posts: 2
|
Posted: Mon Feb 21, 2005 9:45 am Post subject: Linker option |
|
|
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 |
|
 |
mkcolg
Joined: 30 Jun 2004 Posts: 4996 Location: The Portland Group Inc.
|
Posted: Mon Feb 21, 2005 12:41 pm Post subject: |
|
|
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 |
|
 |
zzzhong
Joined: 23 Dec 2004 Posts: 2
|
Posted: Tue Feb 22, 2005 11:18 am Post subject: |
|
|
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 |
|
 |
mkcolg
Joined: 30 Jun 2004 Posts: 4996 Location: The Portland Group Inc.
|
Posted: Tue Feb 22, 2005 12:39 pm Post subject: |
|
|
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 |
|
 |
|
|
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 © 2001, 2002 phpBB Group
|