0
C++ (Windows 7 + minGW + Python 2.7.2 + Eclipse Indigo with CDT and PyDev)
에 파이썬 코드를 임베드하려고합니다.파이썬 코드를 C++ (Windows + minGW + Python 2.7.2 + Eclipse)에 포함하기
그래서,이 간단한 코드입니다 :
#include <Python.h> //Python.h
#include <iostream> //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;
}
그리고 나는 내가 뭘 잘못 understant 없습니다. C:\Python27\include
및 C:\Python27\lib
개의 파일을 포함하지만 프로젝트를 빌드 할 수 없습니다. 내 프로젝트를 빌드하려고 할 때
1)이 오류가있어 :
**** 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.
2) 내가 .. "는 MinGW"에서 "CrossGCC"에서 이클립스에서 현재 툴체인을 변경하면이 오류를 가지고 :
**** 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 ****
사람이 내 코드 또는 설정 또는 뭔가 다른 뭐가 잘못 말해 주시겠습니까?
당신에게 링커 오류가 아닌 컴파일러 오류가
감사로 변경해야합니다! 그것은 작동하지만 작은 변화 .. 대신 - lpython 나는 -lpython27을 붙인다. 이제 나는 다음을 얻었습니다 : Cross G ++ 링커 g ++ -LC :/Python27/libs -lpython27 -L "C : \ Python27 \ libs"-L "C : \ Python27 \ include"-o "testpy.exe"./main .o -lpython27 – pupadupa