iostream doesn't work (clang++)

Mark Geisert mark@maxrnd.com
Wed Jul 5 03:06:26 GMT 2023


Hi again,

ggl329 via Cygwin wrote:
> Hi,
> 
> clang++ fails with iostream.
> Does it go well in your environment?
> # I noticed that clang is orphaned. clang requires a maintainer?

It would indeed be nice to have a clang maintainer.  Until that happens various 
other folks might be able to assist if their schedules allow.

> $ cat sample.cc
> #include <iostream>
> int main()
> {
>      std::cout << "Hello World.\n";
>      return 0;
> }
> 
> $ g++ sample.cc
> $ ./a
> Hello World.
> 
> $ clang++ sample.cc
> In file included from sample.cc:1:
> In file included from /usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/iostream:39:
> In file included from /usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/ostream:38:
> In file included from /usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/ios:42:
> In file included from 
> /usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/bits/ios_base.h:39:
> In file included from 
> /usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/ext/atomicity.h:35:
> In file included from 
> /usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/x86_64-pc-cygwin/bits/gthr.h:148:
> In file included from 
> /usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/x86_64-pc-cygwin/bits/gthr-default.h:35:
> In file included from /usr/include/pthread.h:11:
> In file included from /usr/include/sys/types.h:221:
> In file included from /usr/include/sys/_pthreadtypes.h:12:
> /usr/include/sys/cpuset.h:45:24: error: use of undeclared identifier 
> '__builtin_malloc'; did you mean
>        '__builtin_alloca'?
>    return (cpu_set_t *) __builtin_malloc (CPU_ALLOC_SIZE(num));
>                         ^
> /usr/include/sys/cpuset.h:45:24: note: '__builtin_alloca' declared here
> /usr/include/sys/cpuset.h:52:3: error: use of undeclared identifier '__builtin_free'
>    __builtin_free (set);
>    ^
> 2 errors generated.
> 
> 
> Package version information which may be related.
> 
> Cygwin Package Information
> Package              Version
> binutils             2.40-1
> clang                8.0.1-1
> compiler-rt          8.0.1-1
> cygwin               3.4.7-1
> cygwin-devel         3.4.7-1
> gcc-core             11.4.0-1
> gcc-g++              11.4.0-1
> libc++-devel         8.0.1-1
> libc++1              8.0.1-1
> libc++abi-devel      8.0.1-1
> libc++abi1           8.0.1-1
> libclang-devel       8.0.1-1
> libclang8            8.0.1-1
> libllvm-devel        8.0.1-1
> libllvm8             8.0.1-1
> libpolly-devel       8.0.1-1
> libpolly8            8.0.1-1
> libstdc++6           11.4.0-1
> libunwind-devel      8.0.1-1
> libunwind1           8.0.1-1
> llvm                 8.0.1-1

My previous reply addressed the specific error reported by your testcase.  But I 
am unable to make progress on the root cause because I can't reproduce your report.

On my system I try the compilation and see:
~ clang++ sample.cc
sample.cc:1:10: fatal error: 'iostream' file not found
#include <iostream>
          ^~~~~~~~~~
1 error generated.

My list of possibly related package versions looks very similar to yours:
binutils           2.40-1
clang              8.0.1-1
compiler-rt        8.0.1-1
cygwin             3.4.7-1
cygwin-devel       3.4.7-1
gcc-core           11.4.0-1
gcc-g++            11.4.0-1
libatomic1         11.4.0-1
libc++-devel       8.0.1-1
libc++1            8.0.1-1
libc++abi-devel    8.0.1-1
libc++abi1         8.0.1-1
libclang-devel     8.0.1-1
libclang8          8.0.1-1
libgcc1            11.4.0-1
libllvm-devel      8.0.1-1
libllvm8           8.0.1-1
libpolly-devel     8.0.1-1
libpolly8          8.0.1-1
libquadmath0       11.4.0-1
libstdc++6         11.4.0-1
libunwind-devel    8.0.1-1
libunwind1         8.0.1-1
llvm               8.0.1-1

I'm not a clang user so there might be something fundamentally wrong with my setup 
that I don't see.  Also, do you have a CFLAGS or other environment string(s) that 
would possibly be passed to clang as it would to gcc?  Has "clang++" been aliased 
to something else, perhaps passing options that way?  Also, do you happen to have 
any of the boost libraries installed?

I'm willing to patch the reported error but I'd like to first make sure it is 
legitimate for clang to have gone down the reported include path through what look 
like gcc-related include files.

..mark


More information about the Cygwin mailing list