0

I'm trying to install gcc-5.0 from source on my OS X 10.7.5 using the (Apple built) /usr/bin/gcc-4.2 and the appropriate versions of gcc dependencies (gmp,mpfr,mpc) which are installed at /usr/local.

The reason I'm trying to (re)install gcc-5.0 is because I want to install it into a separate folder like /usr/local/gcc-5.0 so that I can choose to use or not us it easily by setting it into the PATH environment variable. The /configure script is (initiated from an empty gcc-5.0-build folder)

../gcc-5.0.0/configure --prefix=/usr/local/gcc-5.0.0 --with-gmp=/usr/local/lib --with-mpfr=/usr/local/lib --with-mpc=/usr/local/lib --enable-languages=c,c++

After make and about 1GB of compiled files I get this error (truncated)

dyld: Symbol not found: __ZNKSt11logic_error4whatEv
  Referenced from: <my-build-dir>/x86_64-apple-darwin11.4.0/libstdc++-v3/src/.libs/libstdc++.6.dylib
  Expected in: flat namespace

After browsing many webpages and posts in Stackoverflow, I've tried various things like:

adding LDFLAGS="-flat_namespace"before ./configure

compiling with Apple built gcc-4.2 instead of gcc-5.0

but no luck I still end up with this error.

When I check the libstdc++.6.dylib on the presence of __ZNKSt11logic_error4whatEv

nm -g x86_64-apple-darwin11.4.0/libstdc++-v3/src/.libs/libstdc++.6.dylib | grep  __ZNKSt11logic_error4whatEv

It returns:

U __ZNKSt11logic_error4whatEv

so itcontains the symbol in question It doesn't contain the symbol in question (The U means Undefined)

otool -hv x86_64-apple-darwin11.4.0/libstdc++-v3/src/.libs/libstdc++.6.dylib

returns

Mach header
      magic cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
MH_MAGIC_64  X86_64        ALL  0x00       DYLIB    13       2560   NOUNDEFS DYLDLINK TWOLEVEL WEAK_DEFINES BINDS_TO_WEAK NO_REEXPORTED_DYLIBS

The DYLDLINK TWOLEVEL means that it's two-level namespace lib.

Questions :

1- In the message Expected in: flat namespace does it mean that the compiler wants absolutely only the flat namespace library? I mean is it absolutely not possible to use this two-level namespace lib? After a comment by @G.M. the symbol is not defined in the library in question and that makes the absence or presence of flat namespace irrelevant because it is the content of the library which causes the problem, not its type.

2- What should I do compile the gcc-5.0 ?

Update 23.March.2021

Upon the answer suggesting hiding the symbols, I've added

export CFLAGS="-fvisibility=hidden"

onto the ~/.bash_profile deleted the build folder all over, configured again using

../gcc-5.0.0-20150224/configure --prefix=/usr/local/gcc-5.0.0 --enable-languages=c,c++

and after make has created 532MB of compiled files, it stopped by the strip: symbols names listed in:libgcc-darwin.10.4.ver not in libgcc_s.dylib type of error. Here is how it stopped:

/Users/thompson/Downloads/gcc-5.0.0-20150224-mybuild/./gcc/xgcc -B/Users/thompson/Downloads/gcc-5.0.0-20150224-mybuild/./gcc/ -B/usr/local/gcc-5.0.0/x86_64-apple-darwin11.4.2/bin/ -B/usr/local/gcc-5.0.0/x86_64-apple-darwin11.4.2/lib/ -isystem /usr/local/gcc-5.0.0/x86_64-apple-darwin11.4.2/include -isystem /usr/local/gcc-5.0.0/x86_64-apple-darwin11.4.2/sys-include    -O2  -g -O2 -fvisibility=hidden -DIN_GCC    -W -Wall -Wwrite-strings -Wcast-qual -Wno-format -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition  -isystem ./include   -pipe -fno-common -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector  -dynamiclib -nodefaultlibs -install_name /usr/local/gcc-5.0.0/lib/libgcc_s.1.dylib -single_module -o ./libgcc_s.dylib -Wl,-exported_symbols_list,libgcc.map -compatibility_version 1 -current_version 1.0 -g -O2 -fvisibility=hidden -B./ _muldi3_s.o _negdi2_s.o _lshrdi3_s.o _ashldi3_s.o _ashrdi3_s.o _cmpdi2_s.o _ucmpdi2_s.o _clear_cache_s.o _trampoline_s.o __main_s.o _absvsi2_s.o _absvdi2_s.o _addvsi3_s.o _addvdi3_s.o _subvsi3_s.o _subvdi3_s.o _mulvsi3_s.o _mulvdi3_s.o _negvsi2_s.o _negvdi2_s.o _ctors_s.o _ffssi2_s.o _ffsdi2_s.o _clz_s.o _clzsi2_s.o _clzdi2_s.o _ctzsi2_s.o _ctzdi2_s.o _popcount_tab_s.o _popcountsi2_s.o _popcountdi2_s.o _paritysi2_s.o _paritydi2_s.o _powisf2_s.o _powidf2_s.o _powixf2_s.o _powitf2_s.o _mulsc3_s.o _muldc3_s.o _mulxc3_s.o _multc3_s.o _divsc3_s.o _divdc3_s.o _divxc3_s.o _divtc3_s.o _bswapsi2_s.o _bswapdi2_s.o _clrsbsi2_s.o _clrsbdi2_s.o _fixunssfsi_s.o _fixunsdfsi_s.o _fixunsxfsi_s.o _fixsfdi_s.o _fixdfdi_s.o _fixxfdi_s.o _fixunssfdi_s.o _fixunsdfdi_s.o _fixunsxfdi_s.o _floatdisf_s.o _floatdidf_s.o _floatdixf_s.o _floatundisf_s.o _floatundidf_s.o _floatundixf_s.o _fixsfti_s.o _fixdfti_s.o _fixxfti_s.o _fixtfti_s.o _fixunssfti_s.o _fixunsdfti_s.o _fixunsxfti_s.o _fixunstfti_s.o _floattisf_s.o _floattidf_s.o _floattixf_s.o _floattitf_s.o _floatuntisf_s.o _floatuntidf_s.o _floatuntixf_s.o _floatuntitf_s.o _divdi3_s.o _moddi3_s.o _udivdi3_s.o _umoddi3_s.o _udiv_w_sdiv_s.o _udivmoddi4_s.o darwin-64_s.o cpuinfo_s.o sfp-exceptions_s.o addtf3_s.o divtf3_s.o eqtf2_s.o getf2_s.o letf2_s.o multf3_s.o negtf2_s.o subtf3_s.o unordtf2_s.o fixtfsi_s.o fixunstfsi_s.o floatsitf_s.o floatunsitf_s.o fixtfdi_s.o fixunstfdi_s.o floatditf_s.o floatunditf_s.o fixtfti_s.o fixunstfti_s.o floattitf_s.o floatuntitf_s.o extendsftf2_s.o extenddftf2_s.o extendxftf2_s.o trunctfsf2_s.o trunctfdf2_s.o trunctfxf2_s.o enable-execute-stack_s.o unwind-dw2_s.o unwind-dw2-fde-darwin_s.o unwind-sjlj_s.o unwind-c_s.o emutls_s.o libgcc.a -lc

ld: warning: cannot export hidden symbol ___ashldi3 from darwin-64_s.o
ld: warning: cannot export hidden symbol ___ashrdi3 from darwin-64_s.o
ld: warning: cannot export hidden symbol ___clzsi2 from darwin-64_s.o
ld: warning: cannot export hidden symbol ___cmpdi2 from darwin-64_s.o
<truncated>
ld: warning: cannot export hidden symbol ___fixunstfsi from fixunstfsi_s.o
ld: warning: cannot export hidden symbol ___floatsitf from floatsitf_s.o
<truncated>
ld: warning: cannot export hidden symbol ___enable_execute_stack from enable-execute-stack_s.o
<truncated>
ld: warning: cannot export hidden symbol ___emutls_register_common from emutls_s.o

MLIBS=`/Users/thompson/Downloads/gcc-5.0.0-20150224-mybuild/./gcc/xgcc -B/Users/thompson/Downloads/gcc-5.0.0-20150224-mybuild/./gcc/ -B/usr/local/gcc-5.0.0/x86_64-apple-darwin11.4.2/bin/ -B/usr/local/gcc-5.0.0/x86_64-apple-darwin11.4.2/lib/ -isystem /usr/local/gcc-5.0.0/x86_64-apple-darwin11.4.2/include -isystem /usr/local/gcc-5.0.0/x86_64-apple-darwin11.4.2/sys-include    --print-multi-lib | sed -e 's/;.*$//'` ; \
    for mlib in $MLIBS ; do \
      cp ../${mlib}/libgcc/${mlib}/libgcc_s.dylib  \
        ./libgcc_s.1.dylib_T_${mlib} || exit 1 ; \
    done

lipo -output libgcc_s.1.dylib \
      -create libgcc_s.1.dylib_T*
rm libgcc_s.1.dylib_T*

<truncated>

strip: symbols names listed in: <source-folder>/libgcc/config/i386/libgcc-darwin.10.4.ver not in: </Users/thompson/Downloads/gcc-5.0.0-20150224-mybuild>/x86_64-apple-darwin11.4.2/libgcc/libgcc_s.dylib
___ashldi3
___ashrdi3
___clzsi2
___cmpdi2
___ctzsi2
___divdi3
___enable_execute_stack
___gcc_personality_v0
___lshrdi3
___moddi3
___muldi3
___negdi2
___paritysi2
___popcountsi2
___ucmpdi2
___udivdi3
___udivmoddi4
___umoddi3
make[3]: *** [libgcc_ext.10.4.dylib] Error 1
make[2]: *** [all-stage1-target-libgcc] Error 2
Terry
  • 1,206
  • 1
  • 10
  • 26
  • I'd recommend either sticking with the apple supplied version (which is very old), use homebrew to get a newer verison or just use the supported compiler on macos which is clang. – Alan Birtles Oct 13 '19 at 17:38
  • The apple supplied version, `gcc-4.2` is present on my system and it doesn't matter if I use it or the (GNU suppiled) `gcc-5.0` version to compile the `gcc-5.0` they both give the same `expected in: flat namespace` error. – Terry Oct 13 '19 at 17:54
  • What I'm saying is compiling GCC is a long, sometimes tricky and boring task, don't bother trying and use homebrew or clang insead – Alan Birtles Oct 13 '19 at 18:35
  • 3 years ago I managed to compile `gcc-5.0` from source on this same Mac. Actually, it's compiling all the files without any problem: Over 1GB compiled files are there in the build folder. The *symbol not found* errors are usually fixed by working out the possible library mismatches, adding some linker flags, etc. I've given up using Homebrew years ago as it's got its own problems really. But I will search for the solution possibilities with Clang. – Terry Oct 13 '19 at 19:13
  • 1
    I'm not sure but... the output you see from `nm` begins with `U`. That usually means undefined. That implies your `libstdc++` *references* the symbol but does *not* contain its definition. – G.M. Oct 13 '19 at 19:17
  • You're correct, It turns out that `U` really means that the symbol is undefined. In this case it's very likely that the error was not caused by the absence of the `flat namespace` i.e. it's just a distraction. So the real problem is that the library contains the symbol but not its definition. That seems to answer my 1st question. I will edit the post. – Terry Oct 13 '19 at 20:29

1 Answers1

1

I suffered the same error while running my application in release mode. After two days searching I manage to resolve it by turning the Symbols Hidden by Default off in the dynamic library project build settings. Hope this is helpful to you and others with the same error.

Vichal
  • 55
  • 6
  • Thank you for the answer. That answer must have escaped my attention because it came at a time when the pandemic was at its peak worldwide. Now I've applied it by adding `export CFLAGS="-fvisibility=hidden"` in `~/.bash_profile` and the build has stopped at an earlier phase (when the compiled files were 527MB, compared to about 1GB) and it gave strip: symbols names listed in: `libgcc-darwin.10.4.ver` not in `libgcc_s.dylib` type of error. Because the error is too long to fit here, I've added it onto the main post. See the post edited. – Terry Mar 23 '21 at 08:41