Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 642
Ladih Avatar asked Dec 02 '25 13:12

Ladih


1 Answers

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).

like image 78
BiagioF Avatar answered Dec 05 '25 01:12

BiagioF



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!