I wrote a simple C++ program.

#include <vector>

int main(void) {
    return 0;

When I try to compile with clang, I get this :

$ clang truc.c        
truc.c:1:10: fatal error: 'vector' file not found
#include <vector>
1 error generated.

When I try to compile with g++, I get this :

$ g++ truc.c 
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]

What can I do to make it so that clang works too? I have Xcode 11.2, CommandLineTools for 11.2, OSX 10.15.1.

I ran

xcode-select --install

sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

Alternatively, I could not use clang and use g++ instead. I have to use a specific repo for school and they use scons and I don't really how to deal with that.

  • <vector> is C++ not C. See why do i need to include <vector> to use them?. If you want a simple C program try this. In any case, programming questions are better asked on stackoverflow. – lx07 Dec 4 '19 at 16:48
  • updated my post. i believe this is a osx related issue. – truvaking Dec 4 '19 at 18:41
  • As it is C++ then if you rename truc.c to truc.C (case matters), truc.cpp,truc.cc (etc) clang will compile it fine. g++ will compile it but give a warning (because you've told it it is C++ by using C++ compiler). Clang direct will not compile it as you've used .c which is for C programs by default. I don't really see this is a macOS issue. – lx07 Dec 4 '19 at 19:26
  • Mh.. It did resolve the issue. My apologies, I really thought the file extension carried no information whatsoever. Thanks, I guess it's not my xcode setup that is broken. – truvaking Dec 4 '19 at 19:35

You must log in to answer this question.

Browse other questions tagged .