0

1.Install LLVM brew install llvm@12

2.create dest.cpp

#include <bits/stdc++.h>
  // code

3.when i run /opt/homebrew/opt/llvm@12/bin/clang++ dest.cpp -o dest, i get:

fatal error: 'bits/stdc++.h' file not found

1.i add directory bits which contains a file stdc++.h to path : /opt/homebrew/Cellar/llvm@12/12.0.1_1/Toolchains/LLVM12.0.1.xctoolchain/usr/include, i get the same fatal

2.i add it to /opt/homebrew/Cellar/llvm@12/12.0.1_1/include too, but result is the same

PS.the stdc++.h file is correct, because I use it successful when I add it /Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/usr/include, but it does not work when i add it to llvm@12

I have to have stdc++.h here because my work is to test hundreds of codes and most of them have the stdc++.h, it is too difficult for me to change the headers to what they exactly need.

what is the trouble? is it possible to have stdc++.h while I run /opt/homebrew/opt/llvm@12/bin/clang++?

  • 1
    https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h – Mat Apr 19 '23 at 19:46

2 Answers2

2

bits/stdc++.h is a libstdc++-specific header file.

On Mac OS, the standard library is libc++, which does not have that file. (it's a non-standard implementation detail of libstdc++).

If you are unwilling/unable to change your source files, I can think of two options:

  • Install libstdc++ on your Mac. This will probably work, but (I believe) that Mac OS is not a supported platform for libstdc++.

  • Create your own file stdc++.h and put it in a folder named bits and point clang at it. You'll need to figure out what to put into the file.

Marshall Clow
  • 15,972
  • 2
  • 29
  • 45
  • thanks for your answer, but in the second option, i still need to change de source files, because the source code is ```#include ```, and if i use my own file stdc++.h, i need to change it to ```#include "bits/stdc++.h"``` – Adah_250 Apr 20 '23 at 09:03
0

Try using -I /path/to/headerfile option with Clang++ to let the compiler know where else to search for the header files that are not found in its standard search directories:

clang++ dest.cpp -o dest -I /path/to/bits

Farzam
  • 131
  • 2
  • 13
  • i run this command and get ```error: 'bits/stdc++.h' file not found with include; use "quotes" instead ``` then i have to change ```#include```to ```#include "bits/stdc++.h"``` , is there a way to solve it without changing the dest.cpp? – Adah_250 Apr 20 '23 at 08:58
  • Yes. In order to have separate control over the search paths use `-iquote` for quote-formatted includes and `-isystem` for angle-bracket forms of include. So in your case, you can use `-isystem` instead of `-I` and this way you will not need to change your code. – Farzam Apr 20 '23 at 18:07