Use of lang/gcc*'s g++* via the likes of USE_GCC=11:build+ in ports when a -Wl,-rpath=/usr/local/lib/gcc* is required: How?

From: Mark Millard <>
Date: Mon, 18 Apr 2022 02:21:11 UTC
I'll use g++11 as an example here. By no means is the issue
limited to g++11 . Also, the general issue is not limited
to the specifics of the other aspects of the example I report


FreeBSD's /lib/ is insufficient for what aarch64
g++11 code generation expects to be provided. Programs can be
built but end up with notices that start with: /lib/ version GCC_4.5.0 required by
. . . not found

Sometimes the ". . ." is /usr/local/lib/gcc11/ .
Other times it does not get that far because the program
itself has the issue before shared libraries are bound. A
simple 6 line program on aarch64 can show the issue:

# more fp-binding-failure-aarch64.cpp
#include <cmath>
volatile long double v=NAN;
int main()
    return std::isnan(v) ? 1 : 0;

# g++11 fp-binding-failure-aarch64.cpp
# ./a.out /lib/ version GCC_4.5.0 required by /usr/home/root/c_tests/a.out not found

The a.out has its own reference to 
__unordtf2@GCC_4.5.0 :

# nm -a a.out | grep '@GCC_[4-9]\.' | more

For reference . . .

# ldd a.out
a.out: => /usr/local/lib/gcc11/ (0x83000000) => /lib/ (0x81834000) => /lib/ (0x8275a000) => /lib/ (0x845f3000)

Use of -Wl,-rpath=/usr/local/lib/gcc11 avoids the example's
failure by using gcc11's instead of FreeBSD's.
gcc11's is more likely to accurately cover
the g++11 compiler's potential range of code generation.

I've no clue what all g++11 targeting aarch64 generates that
also would not be found in /lib/ on aarch64.

Similarly, I do not know what examples might exist for other
FreeBSD platforms. But aarch64 is tier 1 these days, if that
matters for this subject area.


How does one use the likes of USE_GCC=11:build+ and also
supply the appropriate -Wl,-rpath=/usr/local/lib/gcc??
to match which g++ is actually used?

There is an analogous question for when using a linker
command line directly instead (no -Wl, prefix).

Mark Millard
marklmi at