Bug 230184

Summary: clang++ failed to include standard header files if '-stdlib=libstdc++' option is specified
Product: Base System Reporter: Yasuhiro Kimura <yasu>
Component: binAssignee: freebsd-toolchain (Nobody) <toolchain>
Status: Open ---    
Severity: Affects Some People CC: dim, marklmi26-fbsd, thanos17997
Priority: ---    
Version: CURRENT   
Hardware: Any   
OS: Any   
Bug Depends on:    
Bug Blocks: 230185    

Description Yasuhiro Kimura freebsd_committer freebsd_triage 2018-07-30 09:18:02 UTC
In the OPTIONS section of clang(1) man page '-stdlib' option is
explained as following:

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

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 \
		cpptest02
OBJECTS =	cpptest01.o \
		cpptest02.o

all: ${TARGETS}

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

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

clean:
	${RM} ${TARGETS} ${OBJECTS}
yasu@rolling-vm-freebsd1[1726]% cat cpptest01.cpp
#include <iostream>

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

int
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.
yasu@rolling-vm-freebsd1[1728]%
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 freebsd_triage 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 freebsd_committer freebsd_triage 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
MARKED AS SPAM