Opened 7 years ago

Closed 7 years ago

#54599 closed defect (invalid)

gcc6 @6.4.0: g++ rejects flag "-stdlib"

Reported by: mouse07410 (Mouse) Owned by:
Priority: Normal Milestone:
Component: ports Version:
Keywords: Cc:
Port: gcc6

Description

MacOS Sierra 10.12.6, Xcode-8.3.3, current Macports, Macports-installed GCC/G++:

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin16/6.4.0/lto-wrapper
Target: x86_64-apple-darwin16
Configured with: /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_lang_gcc6/gcc6/work/gcc-6.4.0/configure --prefix=/opt/local --build=x86_64-apple-darwin16 --enable-languages=c,c++,objc,obj-c++,lto,fortran --libdir=/opt/local/lib/gcc6 --includedir=/opt/local/include/gcc6 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-6 --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-6 --with-gxx-include-dir=/opt/local/include/gcc6/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-isl=/opt/local --enable-stage1-checking --disable-multilib --enable-lto --enable-libstdcxx-time --with-build-config=bootstrap-debug --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket --disable-tls --with-pkgversion='MacPorts gcc6 6.4.0_0'
Thread model: posix
gcc version 6.4.0 (MacPorts gcc6 6.4.0_0) 
$ g++ -std=c++11 -stdlib=libc++ -o tfd -I/opt/local/include tf.cpp -L/opt/local/lib -lecm -lgmpxx -lgmp -lc++
g++: error: unrecognized command line option '-stdlib=libc++'
$ 

Change History (6)

comment:1 Changed 7 years ago by kencu (Ken)

yep -- a little tough to help without knowing what port this is -- if in fact this is a port you're trying to build.

gcc does not handle the -stdlib flag.

Just delete it from your build line. Or use clang, which does handle it, if you prefer that.

comment:2 Changed 7 years ago by mouse07410 (Mouse)

yep -- a little tough to help without knowing what port this is -- if in fact this is a port you're trying to build.

Darn... Silly me. The port I'm complaining about is gcc6:

$ port info gcc6
gcc6 @6.4.0 (lang)
Sub-ports:            libgcc
Variants:             universal

Description:          The GNU compiler collection, including front ends for C, C++, Objective-C, Objective-C++, and Fortran.
Homepage:             http://gcc.gnu.org/

Extract Dependencies: xz
Library Dependencies: cctools, gmp, isl, ld64, libgcc, libiconv, libmpc, mpfr
Runtime Dependencies: gcc_select
Platforms:            darwin
License:              {GPL-3+ Permissive}
Maintainers:          none

gcc does not handle the -stdlib flag.

And this is the essence of my complaint - because for the C++ code I'm compiling/linking I need to be able to tell g++ to use libc++ instead of libstdc++. Otherwise it won't be able to link with other libraries that are compiled for libc++. Which is why I cannot "just delete "-stdlib" from the build line - I'd get something like

$ g++ -std=c++11 -o tfd -I/opt/local/include tf.cpp -L/opt/local/lib -lecm -lgmpxx -lgmp -lc++
Undefined symbols for architecture x86_64:
  "operator<<(std::basic_ostream<char, std::char_traits<char> >&, __mpz_struct const*)", referenced from:
      std::basic_ostream<char, std::char_traits<char> >& operator<< <__mpz_struct [1], __mpz_struct [1]>(std::basic_ostream<char, std::char_traits<char> >&, __gmp_expr<__mpz_struct [1], __mpz_struct [1]> const&) in ccUkMPud.o
  "operator>>(std::basic_istream<char, std::char_traits<char> >&, __mpz_struct*)", referenced from:
      std::basic_istream<char, std::char_traits<char> >& operator>><__mpz_struct [1]>(std::basic_istream<char, std::char_traits<char> >&, __gmp_expr<__mpz_struct [1], __mpz_struct [1]>&) in ccUkMPud.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

comment:3 Changed 7 years ago by kencu (Ken)

Thanks. If you're on 10.6 or later, you should use clang++ instead of g++. So your build line would be something like this:

/opt/local/bin/clang++-mp-4.0 -stdlib=libc++ -std=c++11  -I/opt/local/include -L/opt/local/lib -lecm -lgmpxx -lgmp -o tfd tf.cpp 

you don't need -lc++ if you use -stdlib=libc++.

Last edited 7 years ago by kencu (Ken) (previous) (diff)

comment:4 Changed 7 years ago by kencu (Ken)

If you really, really need to use gcc6 instead of clang, there is a way. <http://libcxx.llvm.org/docs/UsingLibcxx.html> will show you. I suggest you use clang++ instead, however.

comment:5 Changed 7 years ago by mouse07410 (Mouse)

Thank you! Let me experiment with this, following your recommendations.

comment:6 Changed 7 years ago by ryandesign (Ryan Carsten Schmidt)

Port: gcc6 added
Resolution: invalid
Status: newclosed
Summary: g++ rejects flag "-stdlib"gcc6 @6.4.0: g++ rejects flag "-stdlib"

Not our bug. Complain to developers of gcc if needed.

Note: See TracTickets for help on using tickets.