# error when including iostream

This topic is 2142 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm getting a runtime error when I include iostream in my program. This is the error:

Program received signal SIGSEGV, Segmentation fault.
In ntdll!RtlpWaitForCriticalSection () (C:\WINDOWS\system32\ntdll.dll)

I'm using Code::Blocks on windows XP.
Any ideas on how to fix this?

##### Share on other sites
How have you deduced that it is the inclusion of <iostream> that is causing this? Does the following program work?

 #include <iostream> int main() { return 0; } 

##### Share on other sites
I tried that code and it doesn't work. But it works if I comment the including of iostream.

##### Share on other sites
Something is seriously bork'd. Have you recently installed the IDE? What versions of code::blocks and compiler are you using? Can you get a stack trace of where the segfault occurs?

##### Share on other sites
I installed the IDE yesterday. I'm using Code::Blocks release 10.05 rev 6283. Here is the stack trace:

#0 7C91B1FA ntdll!RtlpWaitForCriticalSection() (C:\WINDOWS\system32\ntdll.dll:??)
#2 00000000 0x00dae7b0 in ??() (??:??)
#3 77C3B90D msvcrt!_lock() (C:\WINDOWS\system32\msvcrt.dll:??)
#4 77C3EF1A msvcrt!fflush() (C:\WINDOWS\system32\msvcrt.dll:??)
#5 73DAE790 iob() (C:\WINDOWS\system32\crtdll.dll:??)
#6 00000000 0x00000020 in ??() (??:??)
#7 00000000 0x002541b0 in ??() (??:??)
#8 00000000 0x00000001 in ??() (??:??)
#9 00000000 0x00000001 in ??() (??:??)
#10 00000000 0x0022fe14 in ??() (??:??)
#11 00000000 0x0046c2f0 in __DTOR_LIST__() (??:??)
#12 00000000 0x0022ffe0 in ??() (??:??)
#13 77C35C94 msvcrt!_except_handler2() (C:\WINDOWS\system32\msvcrt.dll:??)
#14 00000000 0x0044611f in std::ostream::flush() (??:??)

##### Share on other sites
Which compiler are you using?

I don't believe that Visual C++ 2012 can build Windows XP applications without some semi-serious link-time hackery, in case you happen to be using a pre-release of that.

##### Share on other sites
I'm using mingw compiler 4.4.1-tdm-2.

##### Share on other sites
Can you compile a simple application on the command line that behaves properly? e.g.

C:\path\to\g++ main.cpp -o main.exe -ansi -pedantic

Does 4.4.1-tdm-2 come with Code::Blocks? There are more recent versions of g++ from the official MinGW distribution.

##### Share on other sites
I tried compiling from the command line with the example you gave me and it worked.
Yes, that compiler came with Code::Blocks.

##### Share on other sites
Ok, so what command line is Code::Blocks using to compile/link?

##### Share on other sites
The compiler and linker for dynamic libs is mingw32-g++.exe
The linker for static libs is ar.exe

Don't know if these are necessary:
debugger: gdb.exe
Resource compiler: windres.exe
make program: make.exe

##### Share on other sites
What are the commands that Code::Blocks is issuing? i.e. can you find the exact executable paths and list the command line parameters that are being given to them?

If you can, try to build a small program yourself in exactly the same way. If that program runs correctly, we'll have to look at something else. If Code::Blocks is running your builds through gdb, it could be the particular build of gdb that's at fault.

Alternatively, can you find and run the executable that Code::Blocks built for you and run it directly from explorer or the command shell?

##### Share on other sites
I found what was wrong. In the link libraries list, I had included all the libraries in the MinGW\lib folder.
I am used to doing that, I can't remember why, and I didn't have a problem with it before cause I haven't work on a console project with iostream for a long time.

I removed all the libraries from the link libraries list and it worked fine.Thx

Thanks!