Note that there are some explanatory texts on larger screens.

plurals
  1. POEmbed python code in C++ (Windows + minGW + Python 2.7.2 + Eclipse)
    primarykey
    data
    text
    <p>I'm trying to embed python code in <code>C++ (Windows 7 + minGW + Python 2.7.2 + Eclipse Indigo with CDT and PyDev)</code>.</p> <p>So, this is the simple code:</p> <pre><code>#include &lt;Python.h&gt; //Python.h #include &lt;iostream&gt; //iostream using namespace std; int main(int argc, char *argv[]) { Py_Initialize(); PyRun_SimpleString("from time import time,ctime\n" "print('Today is', ctime(time()))\n"); Py_Finalize(); return 0; } </code></pre> <p>And I couldn't understant what am I doing wrong. I include dirrctories <code>C:\Python27\include</code> and <code>C:\Python27\lib</code>s but I can't build my project.</p> <p>1) When I trying to build my project I got this error:</p> <pre><code>**** Internal Builder is used for build **** g++ -IC:\Python27\include -IC:\Python27\libs -O0 -g3 -Wall -c -fmessage-length=0 -o main.o ..\main.cpp g++ -o testpy2.exe main.o main.o: In function `main': C:\Users\const\workspace\testpy2\Debug/../main.cpp:7: undefined reference to `_imp__Py_Initialize' C:\Users\const\workspace\testpy2\Debug/../main.cpp:9: undefined reference to `_imp__PyRun_SimpleStringFlags' C:\Users\const\workspace\testpy2\Debug/../main.cpp:10: undefined reference to `_imp__Py_Finalize' collect2: ld returned 1 exit status Build error occurred, build is stopped Time consumed: 1507 ms. </code></pre> <p>2) And if I change current toolchain in Eclipse from "minGW" to "CrossGCC" .. I got this error:</p> <pre><code>**** Build of configuration Release for project testpy **** make all Building file: ../main.cpp Invoking: Cross G++ Compiler g++ -I"C:\Python27\include" -I"C:\Python27\libs" -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp" Finished building: ../main.cpp Building target: testpy.exe Invoking: Cross G++ Linker g++ -o "testpy.exe" ./main.o -l"C:/Python27/libs/libpython27.a" -l"C:/Python27/libs/python27.lib" c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe: cannot find -lC:/Python27/libs/libpython27.a c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe: cannot find -lC:/Python27/libs/python27.lib collect2: ld returned 1 exit status make: *** [testpy.exe] Error 1 **** Build Finished **** </code></pre> <p>Could anybody tell me what's wrong with my code or settings or something else?</p> <p>Thank you</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload