Python.h编译错误:collect2.exe Id返回1退出状态

时间:2016-06-21 13:15:20

标签: python c++ dev-c++

所以,我在网上搜索过,但我找不到任何东西。

我开始使用python,我制作了一个TKinter应用程序。起初,我尝试将其编译为.exe文件,但这没有用。所以我现在在C ++中嵌入python。每次我尝试编译它(使用Dev-C ++),我都会收到错误:

C:\Users\*****\AppData\Local\Temp\ccsqSJ5V.o    [program-name].cpp:(.text+0x10): undefined reference to `__imp_Py_Initialize'
C:\Users\*****\AppData\Local\Temp\ccsqSJ5V.o    [program-name].cpp:(.text+0x25): undefined reference to `__imp_PyRun_SimpleStringFlags'
C:\Users\*****\AppData\Local\Temp\ccsqSJ5V.o    [program-name].cpp:(.text+0x2e): undefined reference to `__imp_Py_Finalize'
F:\Documents\Videos\[program-name]\program\collect2.exe [Error] ld returned 1 exit status

F:代表闪存驱动器。 在Dev-c ++选项中,我添加了:

-Wall -I\C:\Users\*****\AppData\Local\Programs\Python\Python35\include

所以这是完整的命令:

g++.exe "F:\Documents\Videos\[program-name]\program\[program-name].cpp" -o "F:\Documents\Videos\[program-name]\program\[program-name].exe" -Wall -I\C:\Users\*****\AppData\Local\Programs\Python\Python35\include -I"C:\Programma's\Dev-C++\MinGW64\include" -I"C:\Programma's\Dev-C++\MinGW64\x86_64-w64-mingw32\include" -I"C:\Programma's\Dev-C++\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include" -I"C:\Programma's\Dev-C++\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++" -I"C:\Users\*****\AppData\Local\Programs\Python\Python35\include" -L"C:\Programma's\Dev-C++\MinGW64\lib" -L"C:\Programma's\Dev-C++\MinGW64\x86_64-w64-mingw32\lib" -static-libgcc

我的问题是:我该如何处理?

请注意:我还没有管理员权限,我只是标准用户。

Python版本:3.5.1
Dev-C ++版本:5.11
GCC版本:我不知道,但如果需要,我会发现它:)

编辑:由于NathanOliver的重复标记,我会这样问:我必须添加哪些命令行变量来编译它?

1 个答案:

答案 0 :(得分:1)

链接器抱怨因为它找不到关于某些python内容的一组引用,事实上我在g ++调用中看不到任何python库。

你需要像这样的-lpython3.5.1告诉g ++链接python库(假设你的系统中安装了python,否则你将不得不使用-L选项添加库的路径)。

有关g ++ makefile和链接的更多资源: https://www3.ntu.edu.sg/home/ehchua/programming/cpp/gcc_make.html