title: C++ Segmentation Fault when using cout in static variable initialization
body: <p>I have a program where I use cout to emit debug information. The code is executed in the initialization of a static global variable, i.e. quite early in the program execution. When I use my own build script to build the program, it segfaults at the first use of cout (only a string literal is shifted into cout, so it cannot be the value). I used valgrind to check for earlier writes to invalid locations, but there are none (and there is also no code that would be likely to generate those writes, I dont do too much before the output). When I copy the source code to an eclipse project and let the eclipse built-in builder build it, then everything works fine. I used no weird builder settings simply compiled with <code>-ggdb -std=c++0x</code>, these are the only two flags.</p>
  
  <p>So what can be the reason that a cout with a string literal segfaults, if there were no invalid writes before? How can the build configuration affect this?</p>
  
  <p>(I am sorry I can give you no minimal example, as this example would simply compile fine at your machine, as it does for me when using the eclipse builder)</p>
  
  <p>Edit: Here is the stacktrace:</p>
  
  <pre><code>0x00007ffff7b6d7d1 in std::ostream::sentry::sentry(std::ostream&amp;) () from /usr/lib   /x86_64-linux-gnu/libstdc++.so.6
  (gdb) backtrace
  #0  0x00007ffff7b6d7d1 in std::ostream::sentry::sentry(std::ostream&amp;) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
  #1  0x00007ffff7b6dee9 in std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp; std::__ostream_insert&lt;char, std::char_traits&lt;char&gt; &gt;(std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;, char const*, long) ()
  from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
  #2  0x00007ffff7b6e2ef in std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp; std::operator&lt;&lt; &lt;std::char_traits&lt;char&gt; &gt;(std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;, char const*) ()
    from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
  #3  0x00000000004021be inTest::fill (this=0x6120f8, funcs=...) at inTest.cpp:92
  </code></pre>
  
  <p>The last frame is my code. Line 92 simply reads:</p>
  
  <pre><code>std::cout &lt;&lt; "Test";
  </code></pre>