Zequan Wu Zequan Wu - 26 days ago 6x
C++ Question

C++ program compiles and runs in codeblocks, but can't compile it in terminal

I created a C++ project that contains several source files and header files. The program compiles and runs well in codeblocks, but I can't compile it in terminal.

All the files are in the same folder.

Here are the command I enter:

clang++ -std=c++11 main.cpp file1.cpp file1.h

It shows:

clang: warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior is deprecated

And a punch of errors about:

error: use of undeclared identifier 'std'

In the head file.


You should to avoid to compile an header file (.h).

Try with:

clang++ -std=c++11 main.cpp file1.cpp

The header file is something that the preprocessor will include in the cpp files which need it (those compilation units which use #include pre-processor directive).