title: g++ with python.h, how to compile
body: <p>I compile one test code with g++ without any issue.</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include "Python.h"  
  
  int main(int argc, char** argv)  
  {  
      Py_Initialize();  
      PyRun_SimpleString("import pylab");  
      PyRun_SimpleString("pylab.plot(range(5))");  
      PyRun_SimpleString("pylab.show()");  
      Py_Exit(0);  
  } 
  </code></pre>
  
  <p><code>g++ -o test test.cpp -I/usr/include/python2.7/ -lpython2.7</code>
  works fine and runs.</p>
  
  <p>But when I try to embed this code into another project, it fails. It really confuses me.</p>
  
  <p>Makefile is like the following.</p>
  
  <pre><code>CXX=g++  
  CXXFLAGS=-DIB_USE_STD_STRING -Wall -Wno-switch -g  
  ROOT_DIR=..  
  BASE_SRC_DIR=${ROOT_DIR}/PosixSocketClient  
  INCLUDES=-I${ROOT_DIR}/Shared/ -I${BASE_SRC_DIR} -I/usr/include/python2.7  
  LIBRARY=-L/usr/lib/python2.7/config  
  TARGET=eu  
  
  $(TARGET):  
      $(CXX) $(CXXFLAGS) $(INCLUDES) -o EClientSocketBase.o -c   $(BASE_SRC_DIR)/EClientSocketBase.cpp  
      $(CXX) $(CXXFLAGS) $(INCLUDES) -o EPosixClientSocket.o -c   $(BASE_SRC_DIR)/EPosixClientSocket.cpp  
      $(CXX) $(CXXFLAGS) $(INCLUDES) -o PosixTestClient.o -c PosixTestClient.cpp  
      $(CXX) $(CXXFLAGS) $(INCLUDES) -o Main.o -c Main.cpp
      $(CXX) $(LIBRARY) -lpython2.7 -o $@ EClientSocketBase.o EPosixClientSocket.o PosixTestClient.o Main.o 
  
  clean:  
      rm -f $(TARGET) *.o  
  </code></pre>
  
  <p>This project compiles fine and runs, the only change I made was adding the test code in the Main.cpp file. warning/error message shows:</p>
  
  <blockquote>
    <p>In file included from /usr/include/python2.7/Python.h:8:0,<br>
                     from Main.cpp:15:<br>
    /usr/include/python2.7/pyconfig.h:1158:0: warning: "_POSIX_C_SOURCE" redefined [enabled by default]<br>
    /usr/include/features.h:163:0: note: this is the location of the previous definition<br>
    /usr/include/python2.7/pyconfig.h:1180:0: warning: "_XOPEN_SOURCE" redefined [enabled by default]<br>
    /usr/include/features.h:165:0: note: this is the location of the previous definition<br>
    g++ -L/usr/lib/ -lpython2.7 -ldl -lutil -o eu EClientSocketBase.o EPosixClientSocket.o PosixTestClient.o Main.o<br>
    Main.o: In function <code>main':<br>
    /home/bbc/TWS/IBJts/cpp/eu-ats/Main.cpp:81: undefined reference to</code>Py_Initialize'<br>
    /home/bbc/TWS/IBJts/cpp/eu-ats/Main.cpp:82: undefined reference to <code>PyRun_SimpleStringFlags'<br>
    /home/bbc/TWS/IBJts/cpp/eu-ats/Main.cpp:83: undefined reference to</code>PyRun_SimpleStringFlags'<br>
    /home/bbc/TWS/IBJts/cpp/eu-ats/Main.cpp:84: undefined reference to <code>PyRun_SimpleStringFlags'<br>
    /home/bbc/TWS/IBJts/cpp/eu-ats/Main.cpp:85: undefined reference to</code>Py_Exit'<br>
    collect2: ld returned 1 exit status<br>
    make: <em>*</em> [eu] Error 1  </p>
  </blockquote>
  
  <p>any help? thank you!</p>