User forums > Help
iostream, string, etc compiled as C instead of C++
i3x171um:
It appears that the stl library is being interpreted as C instead of C++. I get 100+ errors related to basic syntax per build, and pedantic warnings about "C++ style comments not allowed in C files" from any stl header files I include.
What's up? How do I specify that files without extensions be built as C++, or that anything by default be seen as C++?
TDragon:
You should always give your files extensions that reflect the contents -- .c for C source files, .cc or .cpp or .cxx for C++ source files. This is how Code::Blocks and GCC determine whether to compile your files as C or C++.
i3x171um:
STL header files are definitely not supposed to have file extensions.
I'm new to the GNU toolchain. I really would like to use Code::Blocks over Dev C++, but this is a crippling problem (probably with a simple fix).
stahta01:
You are including the header in a source file, what is the source file extension?
We believe it is ".c" which means gcc instead of g++ is being used to compile it by default.
Tim S
i3x171um:
I have driver.cpp and serial.hpp. driver.cpp is writing to the debug stream via cerr, and serial.hpp uses the string and list containers. In driver.cpp I include all my STL headers, then I include serial.hpp.
In short: good guess, but no, I'm including it from a .cpp file which uses the "CPP" compiler flag in compilation, according to the file properties in Code::Blocks.
Navigation
[0] Message Index
[#] Next page
Go to full version