Score:3

clang can't find headers but gcc can

us flag

Using ubuntu 22.04, g++ can compile my test program with no issues. clang++ on the other hand will fail with...

main.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
         ^~~~~~~~~~
1 error generated.
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
  cout << "hello world" << endl;
  return 0;
}

I also have a cmake/c++ project that will compile just fine with gcc, but when I reconfigure it to use clang I get the following output from cmake.

~/C/vkf % cmc && cmake ./ -DCMAKE_BUILD_TYPE=Release -G "Ninja" && ninja
-- The C compiler identification is Clang 14.0.0
-- The CXX compiler identification is Clang 14.0.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: /usr/bin/clang++
-- Check for working CXX compiler: /usr/bin/clang++ - broken
CMake Error at /usr/share/cmake-3.22/Modules/CMakeTestCXXCompiler.cmake:62 (message):
  The C++ compiler

    "/usr/bin/clang++"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/david/C/vkf/CMakeFiles/CMakeTmp
    
    Run Build Command(s):/usr/bin/ninja cmTC_ef4ce && [1/2] Building CXX object CMakeFiles/cmTC_ef4ce.dir/testCXXCompiler.cxx.o
    [2/2] Linking CXX executable cmTC_ef4ce
    FAILED: cmTC_ef4ce 
    : && /usr/bin/clang++   CMakeFiles/cmTC_ef4ce.dir/testCXXCompiler.cxx.o -o cmTC_ef4ce   && :
    /usr/bin/ld: cannot find -lstdc++: No such file or directory
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    ninja: build stopped: subcommand failed.
    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:11 (project)


-- Configuring incomplete, errors occurred!
See also "/home/david/C/vkf/CMakeFiles/CMakeOutput.log".
See also "/home/david/C/vkf/CMakeFiles/CMakeError.log".

in my CMakeError.log

/usr/bin/ld: cannot find -lstdc++: No such file or directory

Something must have been changed in my system configuration, because both of these worked fine before. Does anyone know how to fix it?

Rotartsi avatar
in flag
Was having the exact same problem! Solved by completely uninstalling & reinstalling the `libc++-dev` apt package.
David Carpenter avatar
us flag
tied that, still having the same problem.
Score:2
is flag

Try removing cpp-12 package or install libstdc++-12-dev.

Richard O'Keefe avatar
vu flag
I have had the same problem under 18.04 and 22.04 with clang 10 and clang 14. Installing libc++-dev did not help. Removing cpp-12 did not help. But installing libstdc++-12-dev DID help.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.