Boost logo

Boost-Build :

From: Andre Hentz (ahentz_at_[hidden])
Date: 2004-09-13 14:47:43


Vladimir Prus wrote:

> Andre Hentz wrote:
>
>
>>>1. Why do you need static linking to a specific library?
>>
>> I need a few wrapper programs to link statically against libstdc++ (or
>>libsup++). It is part of the specification that they may run on a system
>>where libstdc++.so is not present.
>
>
> What about using fully static linking with
>
> bjam link=statuc link-runtime=static
>
> ?
>
The issue is more complex than that. First, I need to be selective
about what gets linked statically, which is doable. Second, "link=static
link-runtime=static" also links statically against the libc and does not
allow me to use libsup++ (instead of libstdc++).

>
>>>2. One approach is to use:
>>>
>>> g++ ..... -Wl,-Bstatic -lwhatever
>>>
>>>however this will fail if there's no static version of whatever. Also,
>>>there's assymentry with:
>>>
>>> g++ ..... -Wl,-Bshared -lwhatever
>>>
>>>which will link to whatever.so if present, but will also link with
>>>whatever.a, not fail. Is the '-Bstatic' behaviour what you're after? I'm
>>>a bit worried by its platform-specificity.
>>
>> Yes, that's what I have in mind. If I use <find-static-library>, I
>>expect it to fail if there's no libwhatever.a. In fact, -Bstatic is
>>linker-specific, not platform-specific.
>
>
> Anyway, I don't really like feature which works only sometimes and on some
> linkers. Maybe, <linkflags> is better.

Using <linkflags> to link a library is a bit awkward. For starters, I
don't think I can control library ordering that way. Also, what would be
the point of <find-static-library>, then?

>
>>That is also the case for
>>"-Wl,-R", "-Wl,-h", "-Wl,-rpath-link" and "-Wl,--strip-all". I'm
>>updating my BB setup and haven't got to solaris yet but I believe
>>--strip-all is going to cause problems.
>
>
> I don't think we use it in V2.
>

We do. In fact, it just failed for me on solaris (with sun's LD).
According to the comments in the code, --strip-all is there because icc
doesn't understand -s.

>
>>-rpath-link is also potentialy
>>problematic but I'm not using it so it's not a biggie.
>
>
> I think we have this issue solved on solaris, anyway.

I don't see how it was solved but again I don't use that feature.
gcc.jam does say "-Wl,-rpath-link" and last time I checked sun's LD
does not accept that.

Volodya, allow me to suggest something along the lines of the attached
patch for consideration. I'll happily polish it if people believe it
represents a good alternative. It allows the compiler configuration to
be done like this:

using gcc : : : : <linker>sun ;

And <linker> default to gnu. It may also be possible to automagically
figure out which linker is being used by gcc. The whole point is that
compiler and linker options are orthogonal.

Thanks,

Andre Hentz
 --------------050102070206000605030100 Content-Type: text/plain;
name="patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="patch"

Index: v2/tools/gcc.jam
===================================================================
RCS file: /boost/boost/tools/build/v2/tools/gcc.jam,v
retrieving revision 1.30
diff -u -r1.30 gcc.jam
--- v2/tools/gcc.jam 8 Sep 2004 14:33:04 -0000 1.30
+++ v2/tools/gcc.jam 13 Sep 2004 19:07:30 -0000
@@ -15,6 +15,7 @@
import "class" : new ;
import set ;
import common ;
+import errors ;

feature.extend toolset : gcc ;
toolset.inherit gcc : unix ;
@@ -25,10 +26,26 @@
type.set-generated-target-suffix STATIC_LIB : <toolset>gcc : a ;

+# Goes throuh the given-options and find one that matched
+# <option-name>value. Returns 'value' if found or $(default)
+# otherwise.
+rule get-option ( toolset : option-name : default : given-options ? )
+{
+ local value = $(default) ;
+ for local opt in $(given-options)
+ {
+ if $(opt:G) = "<$(option-name)>"
+ {
+ value = $(opt:G=) ;
+ }
+ }
+ return $(value) ;
+}
+
# Initializes the gcc toolset
# The name parameter specifies the name used to invoke the compiler, and
# can be absolute.
-rule init ( version ? : command * : compiler-options * : linker-options * )
+rule init ( version ? : command * : compiler-options * : linker-options * : options ? )
{
local condition = [ common.check-init-parameters gcc : version $(version) ] ;

@@ -37,6 +54,9 @@
flags gcc CONFIG_COMMAND $(condition) : $(command) ;
flags gcc.compile OPTIONS $(condition) : $(compiler-options) ;
flags gcc.link OPTIONS $(condition) : $(linker-options) ;
+
+ local linker = [ get-option gcc : linker : gnu : $(options) ] ;
+ init-link-flags $(linker) ;
}

if [ os.name ] = NT
@@ -149,32 +169,55 @@

# Declare flags and action for linking
-flags gcc.link OPTIONS <debug-symbols>on : -g ;
-# Strip the binary when no debugging is needed.
-# We use --strip-all flag as opposed to -s since icc
-# (intel's compiler) is generally option-compatible with
-# and inherits from gcc toolset, but does not support -s
-flags gcc.link OPTIONS <debug-symbols>off : -Wl,--strip-all ;
-flags gcc.link OPTIONS <profiling>on : -pg ;
-flags gcc.link OPTIONS <linkflags> ;
-flags gcc.link LINKPATH <library-path> ;
-flags gcc.link FINDLIBS-ST <find-static-library> ;
-flags gcc.link FINDLIBS-SA <find-shared-library> ;
-flags gcc.link LIBRARIES <library-file> ;
-# For <link-runtime>static we made sure there are no dynamic libraries
-# in the link
-flags gcc.link OPTIONS <link-runtime>static : -static ;
-flags gcc.link RPATH <dll-path> ;
-flags gcc.link RPATH_LINK <xdll-path> ;
-
-# This permits shared libraries with non-PIC code on Solaris
-# VP, 2004/09/07: Now that we have -fPIC hardcode in link.dll,
-# the following is not needed. Whether -fPIC should be hardcoded,
-# is a separate question.
-#if [ os.name ] = SOLARIS
-#{
-# flags gcc.link OPTIONS <link>shared : -mimpure-text ;
-#}
+rule init-link-flags ( linker )
+{
+ flags gcc.link OPTIONS <debug-symbols>on : -g ;
+ flags gcc.link OPTIONS <profiling>on : -pg ;
+ flags gcc.link OPTIONS <linkflags> ;
+ flags gcc.link LINKPATH <library-path> ;
+ flags gcc.link FINDLIBS-ST <find-static-library> ;
+ flags gcc.link FINDLIBS-SA <find-shared-library> ;
+ flags gcc.link LIBRARIES <library-file> ;
+ flags gcc.link STATICLIBS_FLAG : -Wl,-Bstatic ;
+ flags gcc.link SHAREDLIBS_FLAG : -Wl,-Bdynamic ;
+ # For <link-runtime>static we made sure there are no dynamic libraries
+ # in the link
+ flags gcc.link OPTIONS <link-runtime>static : -static ;
+ flags gcc.link RPATH <dll-path> ;
+ flags gcc.link RPATH_LINK <xdll-path> ;
+
+ # This permits shared libraries with non-PIC code on Solaris
+ # VP, 2004/09/07: Now that we have -fPIC hardcode in link.dll,
+ # the following is not needed. Whether -fPIC should be hardcoded,
+ # is a separate question.
+ #if [ os.name ] = SOLARIS
+ #{
+ # flags gcc.link OPTIONS <link>shared : -mimpure-text ;
+ #}
+
+ switch $(linker)
+ {
+ case gnu :
+ {
+ # Strip the binary when no debugging is needed.
+ # We use --strip-all flag as opposed to -s since icc
+ # (intel's compiler) is generally option-compatible with
+ # and inherits from gcc toolset, but does not support -s
+ flags gcc.link OPTIONS <debug-symbols>off : -Wl,--strip-all ;
+ }
+ case sun :
+ {
+ flags gcc.link OPTIONS <debug-symbols>off : -Wl,-s ;
+ }
+ case * :
+ {
+ errors.user-error
+ "$(toolset) initialization: invalid linker '$(linker)'" :
+ "The value '$(linker)' specified for <linker> is not recognized." :
+ "Possible values are 'sun', 'gnu'" ;
+ }
+ }
+}

rule link ( targets * : sources * : properties * )
{
@@ -183,7 +226,7 @@

actions link bind LIBRARIES
{
- "$(CONFIG_COMMAND)" $(OPTIONS) -L"$(LINKPATH)" -Wl,-R$(SPACE)-Wl,"$(RPATH)" -Wl,-rpath-link$(SPACE)-Wl,"$(RPATH_LINK)" -o "$(<)" "$(>)" "$(LIBRARIES)" -l$(FINDLIBS-ST) -l$(FINDLIBS-SA)
+ "$(CONFIG_COMMAND)" $(OPTIONS) -L"$(LINKPATH)" -Wl,-R$(SPACE)-Wl,"$(RPATH)" -Wl,-rpath-link$(SPACE)-Wl,"$(RPATH_LINK)" -o "$(<)" "$(>)" "$(LIBRARIES)" $(STATICLIBS_FLAG) -l$(FINDLIBS-ST) $(SHAREDLIBS_FLAG) -l$(FINDLIBS-SA)
}

# Declare action for creating static libraries
@@ -201,7 +244,7 @@
# Differ from 'link' above only by -shared.
actions link.dll bind LIBRARIES
{
- "$(CONFIG_COMMAND)" $(OPTIONS) -L"$(LINKPATH)" -Wl,-R$(SPACE)-Wl,"$(RPATH)" -o "$(<)" -Wl,-h$(SPACE)-Wl,$(<[1]:D=) -shared "$(>)" "$(LIBRARIES)" -l$(FINDLIBS-ST) -l$(FINDLIBS-SA)
+ "$(CONFIG_COMMAND)" $(OPTIONS) -L"$(LINKPATH)" -Wl,-R$(SPACE)-Wl,"$(RPATH)" -o "$(<)" -Wl,-h$(SPACE)-Wl,$(<[1]:D=) -shared "$(>)" "$(LIBRARIES)" $(STATICLIBS_FLAG) -l$(FINDLIBS-ST) $(SHAREDLIBS_FLAG) -l$(FINDLIBS-SA)
}

# Set up threading support. It's somewhat contrived, so perform it at the end,
 --------------050102070206000605030100--


Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk