title: Gnuplot crashes when called from application
body: <p>I'd like to use gnuplot to plot my results in a console application (C++, Eclipse CDT, Linux). I created a simple a class to make things easier (see code below). I try to plot a test plot in my main:</p>
  
  <pre><code>int main() {
  
      Gnuplot plot;
  
      plot("plot sin(x)") ;
  
      cout&lt;&lt;"Press button:";
      cin.get();
  
      return 0;
  }
  </code></pre>
  
  <p>My problem is that if I start my application normally I receive a run-time error message that 'Failed to initialize wxWidgets. Segmentation fault (core dumped)' after executing the line plot("plot sin(x)"). However, if I step through the lines in debug mode the code works fine and my plot window shows up as expected with a sine. Any help would be welcome.</p>
  
  <pre><code>#ifndef GNUPLOT_H_
  #define GNUPLOT_H_
  
  #include &lt;string&gt;
  using namespace std;
  
  class Gnuplot {
  
      public:
          Gnuplot() ;
          ~Gnuplot();
          void operator ()(const string &amp; command); // send any command to gnuplot
  
      protected:
          FILE *gnuplotpipe;
  };
  #endif
  </code></pre>
  
  <p>and the source:</p>
  
  <pre><code>#include "gnuplot.h"
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include "stdio.h"
  
  Gnuplot::Gnuplot() {
  
      gnuplotpipe=popen("gnuplot -persist","w");
      if (!gnuplotpipe) {
      cerr&lt;&lt; ("Gnuplot not found !");
      }
  }
  
  Gnuplot::~Gnuplot() {
  
      fprintf(gnuplotpipe,"exit\n");
      pclose(gnuplotpipe);
  }
  
  void Gnuplot::operator()(const string &amp; command) {
  
      fprintf(gnuplotpipe,"%s\n",command.c_str());
      fflush(gnuplotpipe);// flush is neccessary, nothing gets plotted else
  };
  </code></pre>