clang++ 9.0.1 with -stdlib=libc++ cannot find <optional> - c++

I'm on Manjaro Linux with clang++ 9.0.1.
I'm testing std::optional in C++17. When I compile without -stdlib=libc++, the test cpp file compiles without error. However, if I specify -stdlib=libc++, clang++ shows the following error:
$ clang++ -std=c++17 --stdlib=libc++ test.cpp
test.cpp:4:10: fatal error: 'optional' file not found
#include <optional>
^~~~~~~~~~
1 error generated.
Could you please tell me what I should do if I need to compile it with -stdlib=libc++? Thanks in advance!

Thanks to #nathanoliver and #rian-quinn. I find myself so stupid -- I haven't installed libc++. The error got solved by sudo pacman -S libc++.

Related

Issue with Intel compilation on macOS 10.15 Catalina : catastrophic error: cannot open source file "stdlib.h"

I try desperatly to compile with c++ intel compiler (icpc) a simple code that I was used to compile on my previous macBook 10.14.
Now, since Headers don't exist anymore with 10.15 Catalina, the compiler has difficulties to find stdlib.h. Here the output I get :
icpc -std=c++11 -O3 -xHost -fp-model strict -prec-div -prec-sqrt -fma -ftz -mp1 -qopenmp -Wall -c -I/opt/intel/compilers_and_libraries_2020.2.258/mac/mkl/include -mkl=parallel main.cpp -o main.o
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/math.h(301),
from /opt/intel/compilers_and_libraries_2020.2.258/mac/compiler/include/math.h(177),
from /Library/Developer/CommandLineTools/usr/include/c++/v1/cmath(304),
from TSAF.h(1),
from main.cpp(1):
/Library/Developer/CommandLineTools/usr/include/c++/v1/stdlib.h(20): catastrophic error: cannot open source file "stdlib.h"
#include_next <stdlib.h>
^
compilation aborted for main.cpp (code 4)
make: *** [Makefile:13: main.o] Error 4
./main_intel.exe: No such file or directory
I tried a lot of potential workarounds from the net but none works. I would like to avoid to create a directory /usr/include/ by removing the security system of my macBook.
I thought maybe this would work by downloading XCode_12.0.1 but same problems remain.
For the moment, I have the version Catalina OS 10.15.7, all has been updated.
EDIT 1: There is something that I don't understand : on my previous macBook 10.14, I didn't need to use the headers of clang c++ for intel compilation.
If anyone could give me a suggestion/clue/track, this would be fine.
Run the command in the Terminal
sudo xcode-select --reset
And then check if proper developer tools are selected instead of the command line tools
xcode-select -p

c++ / g++ - Error: Unknown pseudo-op: `. loc'

I am trying to configure my computer to learn C++.
I have errors and warnings once I run gcc from the terminal to call hello.cpp.
C:\Users\Mathieu>gcc -g hello.cpp -o hello -lm
I am using a Windows computer / windows 7 (64 bits) / IDE: Sublime text or Visual Studio Code.
What I have done so far by looking for solutions in the web:
I have added into the PATH the address of MinGW and I have added ";" before the previous PATH.
I have also been checking all the PATH by using echo %PATH% into the terminal and checking the environmental variables.
By typing g++ or gcc alone in the terminal, I get "fatal error, no input file", which means gcc and g++ are well detected by the computer.
I have checked g++ and gcc versions, there are equal.
gcc (MinGW.org GCC Build-20200227-1) 9.2.0
gcc (MinGW.org GCC Build-20200227-1) 9.2.0
I have also performed #alisonc recommandation found here by reviewing links.
g++ 4.6.1 compiler error: Error: unknown pseudo-op: `.cfi_personality'
C:\Users\Mathieu>ls 'which g++' -al
ls: which g++: No such file or directory
C:\Users\Mathieu>ls 'which gcc' -al
ls: which gcc: No such file or directory
When I have launched the program from the terminal I get a long list of errors. I am just adding 3 lines to illustrate. I am not sure if that is relevant to add everything, please, see a few ones:
C:\Users\Mathieu\AppData\Local\Temp\ccUFD66I.s:6498: Error: Unknown pseudo-op:
.secrel32
C:\Users\Mathieu\AppData\Local\Temp\ccUFD66I.s:153: Warning: Missing string
C:\Users\Mathieu\AppData\Local\Temp\ccUFD66I.s:153: Error: Rest of line ignored.
First ignored character is `3'.'''
May someone help me ?
Thank you in advance
All the best
Mathieu
Try to run:
g++ -g hello.cpp -o hello -lm

How can I solve this error on macOS catalina?

I am trying to compile a Cpp program with g++ compiler, but I am getting this error:
Yuliam-MBP:Documents yuliamosh$ g++-9 -std=c++17 -Wall -Wextra -pedantic vector.cpp -o vector
In file included from /usr/local/Cellar/gcc/9.2.0_3/include/c++/9.2.0/bits/postypes.h:40,
from /usr/local/Cellar/gcc/9.2.0_3/include/c++/9.2.0/iosfwd:40,
from /usr/local/Cellar/gcc/9.2.0_3/include/c++/9.2.0/ios:38,
from /usr/local/Cellar/gcc/9.2.0_3/include/c++/9.2.0/ostream:3,
from /usr/local/Cellar/gcc/9.2.0_3/include/c++/9.2.0/iostream:39,
from vector.cpp:1:
/usr/local/Cellar/gcc/9.2.0_3/include/c++/9.2.0/cwchar:44:10: fatal error: wchar.h: No such file or directory
44 | #include <wchar.h>
| ^~~~~~~~~
compilation terminated.
It seems like "wchar.h" was not found.
I would suggest to follow the instructions from this thread.
INSTALL
xcode-select --install
THEN SWITCH TO NEWLY INSTALLED TOOLS
sudo xcode-select --switch /Library/Developer/CommandLineTools/
You might need to reset the default location of the compile tools:
xcode-select --reset
These are the usual fixes. SADLY, NONE OF THEM WORKED FOR ME!
THIS IS WHAT WORKED FOR ME:
Homebrew Solution

clang++ fails to compile hello world

I installed clang in my conda environment along with gcc. Their versions are
gcc 7.2.0
clang 7.0.0
libcxx 7.0.0
I then created an hello world src file a.cpp
If I compile the file using clang++ a.cpp. The error reads
a.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^~~~~~~~~~
1 error generated.
Using clang++ a.cpp --stdlib=libstdc++, the error is the same
Using clang++ a.cpp --stdlib=libc++, the error becomes
~/conda/envs/test/bin/ld: cannot find crtbegin.o: No such file or directory
~/conda/envs/test/bin/ld: cannot find -lgcc
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
Using clang++ a.cpp -I$HOME/conda/envs/test/include/c++/7.2.0
In file included from a.cpp:1:
/site/home/shliu/conda/envs/test/include/c++/7.2.0/iostream:38:10: fatal error: 'bits/c++config.h' file not found
#include <bits/c++config.h>
^~~~~~~~~~~~~~~~~~
1 error generated.
I use a shared computer so I cannot install system wide compilers and header files.
Questions:
What should I do to have it work?
If clang does not ship with its own header files and I need to use what are provided by gcc, should I consider the compatibility of clang version and the gcc version?
Do I need to install libc++ in the same conda environment in order to use clang++?
After some test, I found the way to do it in conda, which is posted as the an answer. However, I still don't understand how clang works, especially its relation with gcc. I would appreciate it very much if any one could answer (and I will accept that as the answer to this post):
Does clang forward all the jobs to gcc so we always need the gcc tool chain to be installed in order to use clang?
I found an include folder for clang, which is $HOME/conda/envs/test/include/c++/v1 alongside with $HOME/conda/envs/test/include/c++/7.2.0 which is from gcc. But if the --gcc-toolchain has been specified, the v1 folder is not searched for headers, (which can be seen from the output by adding -v to the compiler. Then what is the usage of the v1 include files?
Finally I found the way, which is to do
clang++ --gcc-toolchain=$HOME/conda/envs/test a.cpp
This is not obvious at all.

clang++ warning: "warning: unknown warning option '-Wno-maybe-uninitialized'"

Having installed LLVM on Ubuntu 16.04 using the command:
sudo apt-get install clang llvm
I get the following error when compiling:
nlykkei#nlykkei-VirtualBox:~$ clang++ -g toy.cpp `llvm-config --cxxflags --ldflags --system-libs --libs` -o toy
warning: unknown warning option '-Wno-maybe-uninitialized'; did you mean
'-Wno-uninitialized'? [-Wunknown-warning-option]
1 warning generated.
To be specific, I follow the tutorial: http://llvm.org/docs/tutorial/LangImpl03.html on the LLVM website.
The version of LLVM is 3.8.
How do I get rid of this warning?
Thanks.
This is a bug in llvm-config. Long story short, llvm-config outputs -Wno-maybe-uninitialized which is not a warning implemented by clang.
One possible workaround is to add an extra flag squelching warnings about unknown warnings.
clang++ <your flags> -Wno-unknown-warning-option `llvm-config ...`
This warning comes when you recently upgraded your sdk-build-tools with 30.x
I resolved the issue by downgrading sdk-build-tools by 29.x.
Delete all the intermediate files , they will be auto generate again.
Clean Project .
Invalidate Cashes and Restart the Project.
Woow, warning has been removed now.
Answer mentioned here https://github.com/envoyproxy/envoy/issues/18986 might help. Mostly changing Wno-maybe-uninitialized with -Wno-uninitialized in / bazel/envoy_internal.bzl