Bug 230184 - clang++ failed to include standard header files if '-stdlib=libstdc++' option is specified
Summary: clang++ failed to include standard header files if '-stdlib=libstdc++' option...
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-toolchain mailing list
Depends on:
Blocks: 230185
  Show dependency treegraph
Reported: 2018-07-30 09:18 UTC by Yasuhiro KIMURA
Modified: 2019-01-16 08:08 UTC (History)
3 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Yasuhiro KIMURA 2018-07-30 09:18:02 UTC
In the OPTIONS section of clang(1) man page '-stdlib' option is
explained as following:

	Specify the C++ standard library to use; supported options are
	libstdc++ and libc++. If not specified, platform default will be

But if '-stdlib=libstdc++' is specified clang++ fails to include
standard header files such as 'iostream' or 'cstdio'.

yasu@rolling-vm-freebsd1[1724]% uname -a
FreeBSD rolling-vm-freebsd1.home.utahime.org 12.0-CURRENT FreeBSD 12.0-CURRENT #0 r336739: Sun Jul 29 07:46:09 JST 2018     rootz@rolling-vm-freebsd1.home.utahime.org:/usr0/freebsd/base/obj/usr0/freebsd/base/head/amd64.amd64/sys/GENERIC_UTAHIME  amd64
yasu@rolling-vm-freebsd1[1725]% cat Makefile
CXX=		clang++
RM=		rm -f

CXXFLAGS+=	-stdlib=libstdc++

TARGETS =	cpptest01 \
OBJECTS =	cpptest01.o \

all: ${TARGETS}

cpptest01: cpptest01.o
	$(CXX) $(CXXFLAGS) -o $@ $>

cpptest02: cpptest02.o
	$(CXX) $(CXXFLAGS) -o $@ $>

yasu@rolling-vm-freebsd1[1726]% cat cpptest01.cpp
#include <iostream>

main(int argc, char **argv)
    std::cout << "Hello, World" << std::endl;
    return 0;
yasu@rolling-vm-freebsd1[1727]% cat cpptest02.cpp
#include <cstdio>

main(int argc, char **argv)
    std::printf("Hello, World\n");
    return 0;
yasu@rolling-vm-freebsd1[1728]% make -k
clang++  -O2 -pipe -stdlib=libstdc++ -c cpptest01.cpp -o cpptest01.o
cpptest01.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
1 error generated.
*** Error code 1 (continuing)
clang++  -O2 -pipe -stdlib=libstdc++ -c cpptest02.cpp -o cpptest02.o
cpptest02.cpp:1:10: fatal error: 'cstdio' file not found
#include <cstdio>
1 error generated.
*** Error code 1 (continuing)
`all' not remade because of errors.
Comment 1 Mark Millard 2018-07-30 23:27:55 UTC
So far as I know FreeBSD does not provide a modern libstdc++
source code and the old code goes away when gcc 4.2.1 goes
away. libc++ use is for licensing reasons as I understand.

Does FreeBSD intend on supplying a libstdc++? Is some port
supposed to be used to provide the source code for
-std=libstdc++ to find and use?
Comment 2 Dimitry Andric freebsd_committer 2018-08-02 05:33:50 UTC
By default, FreeBSD doesn't include libstdc++ headers and libraries.  To get those, set WITH_GNUCXX in your src.conf, then rebuild world and install it.
Comment 3 Yasuhiro KIMURA 2018-08-02 06:19:16 UTC
(In reply to Dimitry Andric from comment #2)

OK, I understand clang++ works as intended. But anyway it is different from the one described in clang(1) man page. So man page should be fixed so it reflects intended behavior.
Comment 4 Thanos 2019-01-16 08:08:03 UTC