emacs28-nativecomp breaks clang++
Opened this issue · 3 comments
Repro in clean ubuntu:22.04
container:
apt update
apt install -y software-properties-common
add-apt-repository -y ppa:kelleyk/emacs
apt install -y emacs28-nativecomp clang
Try to compile a minimal C++ file like this using clang++ -c foo.cpp -o foo.o
:
#include <string>
std::string foo(std::string x) { return x; }
Results in an error:
foo.cpp:1:10: fatal error: 'string' file not found
#include <string>
^~~~~~~~
1 error generated.
That sounds strange. I also use 22.04 and emacs-nativecomp for C++ without issues, regardless of gcc or clang. Since you’re on a clean install, are you certain that you have installed the C++ standard library? The error message about file string not found sounds like the C++ standard library is missing. Clang doesn’t contain its own standard library so you have to install it separately, which is easiest to do by installing g++.
Even after installing g++
, same error occurs. But using g++
to compile it yields no error.
Wait now I remember that I had a similar problem recently, but with clangd
and not clang
. But clangd
uses clang
, so I suppose the problem probably was with clang
. I had installed the packages called gcc
and g++
, which defaults to gcc-11
and g++-11
. But clangd
was looking for include files in the place where g++-12
would have put its standard library, not where g++-11
would have put it. So what I did was to specifically install g++-12
and then clangd
found the include files. Perhaps you could try that too. This is really stupid, but the c++
ecosystem is trash so I guess this is the kinds of things we have to deal with.
I don't remember which command I used to check clang
's include paths(and I don't have a terminal available atm, so I can't test). But when I checked that, I remember seeing that it does know about both the path to the g++-11
and g++-12
library include paths(even before g++-12
was installed) and the command said afterwards that clang
chose to use the path to the g++-12
library, even though g++-12
wasn't installed at the time.
Another problem I had yesterday was that the g++-12
which was intalled with apt
was not the latest one that Ubuntu offers. I don't know why this happened. I could only install g++ 12.0.1
, but g++ 12.1
is available. But by adding this ppa (which I believe is Canonical's own ppa) I could install the newer g++ 12.1
. For example, one problem I had with g++ 12.0.1
is that std::expected
didn't exist in C++23
. But g++-12
is reported to be the only c++
compiler which has implemented std::expected
, so it should work. When upgrading to g++ 12.1
from the ppa, then std::expected
did indeed exist.