Author Topic: iostream, string, etc compiled as C instead of C++  (Read 4839 times)

i3x171um

  • Guest
iostream, string, etc compiled as C instead of C++
« on: July 18, 2007, 02:52:03 am »
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++?
« Last Edit: July 18, 2007, 02:54:40 am by i3x171um »

Offline TDragon

  • Lives here!
  • ****
  • Posts: 943
    • TDM-GCC
Re: iostream, string, etc compiled as C instead of C++
« Reply #1 on: July 18, 2007, 03:08:58 am »
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++.
https://jmeubank.github.io/tdm-gcc/ - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)

i3x171um

  • Guest
Re: iostream, string, etc compiled as C instead of C++
« Reply #2 on: July 18, 2007, 03:36:35 am »
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).
« Last Edit: July 18, 2007, 03:41:25 am by i3x171um »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: iostream, string, etc compiled as C instead of C++
« Reply #3 on: July 18, 2007, 03:45:45 am »
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
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

i3x171um

  • Guest
Re: iostream, string, etc compiled as C instead of C++
« Reply #4 on: July 18, 2007, 03:56:13 am »
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.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: iostream, string, etc compiled as C instead of C++
« Reply #5 on: July 18, 2007, 04:02:24 am »
In that case we need to verify tool chain executables

"settings" -> "Compiler and Debugger"
Select "Tool Chain Executable" Tab

Verify that "C++ Compiler" is "mingw32-g++.exe"
Note, it could have a full path to it; this helps some Vista and GCC 4.x issues. example, "C:\MinGW\mingw32-g++.exe"

Edit: If the problem still exists please Turn on Full Compiler Logging so we can see the Build Log.

Quote
Settings -> "Compiler Debugger"
Select tab "Other Settings" on far right
Change "Compiler Logging" to "Full Command Line"

Then Try rebuilding and post the "Build Log" Then someone might see the issue cause.

Tim S
« Last Edit: July 18, 2007, 04:10:07 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

i3x171um

  • Guest
Re: iostream, string, etc compiled as C instead of C++
« Reply #6 on: July 18, 2007, 04:15:04 am »
Ah, I figured it out. I had a feeling this is what it was...

In the GCC-G++ include directory, there is a single folder called c++. Inside that, it again has only one folder: 3.4.2. Inside that is the STL, along with some other helper headers.

My obsessive-compulsive-organizer self thought those two levels of folders (/c++/3.4.2/) were unnecessary, so I copied the contents of the 3.4.2 folder straight into the include directory. It turns out, however, that g++ expects the stl to be in include/c++/3.4.2, and chokes if it's not.

My bad. Sorry for the thread.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: iostream, string, etc compiled as C instead of C++
« Reply #7 on: July 18, 2007, 07:13:24 am »
My obsessive-compulsive-organizer self thought those two levels of folders (/c++/3.4.2/) were unnecessary
LOL... Right... :lol: :lol: :lol:
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ