关于Qt连接Python35的问题

zero刹那芳华 2017-03-08 09:08:54
以下是Qt中的代码
pro中
QT += widgets

SOURCES += \
main.cpp

INCLUDEPATH += -I F:\Python35\include\
LIBS += F:\Python35\libs\ -lpython35

DISTFILES += \
B.py

CONFIG += no_keywords

main函数中
#include <QCoreApplication>
#include "Python.h"
#include <QDebug>


int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Py_Initialize();
if (!Py_IsInitialized())
{
return -1;
}
PyObject* pModule = PyImport_ImportModule("B");
if (!pModule) {
qDebug() << "Cant open python file!";
return -1;
}
PyObject* pFunhello= PyObject_GetAttrString(pModule,"hello");
if(!pFunhello) {
qDebug() << "Get function hello failed";
return -1;
}
PyObject_CallFunction(pFunhello,NULL);
Py_Finalize();
return a.exec();
}

python文件中
def hello():
print("hello")


error: undefined reference to `_imp__Py_Initialize'
error: undefined reference to `_imp__Py_IsInitialized'
error: undefined reference to `_imp__PyImport_ImportModule'
error: undefined reference to `_imp__PyObject_GetAttrString'
error: undefined reference to `_imp__PyObject_CallFunction'
error: undefined reference to `_imp__Py_Finalize'
collect2.exe:-1: error: error: ld returned 1 exit status
...全文
269 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhanshenxiaole 2017-03-10
  • 打赏
  • 举报
回复
少了-L LIBS += -L 后面就那样 如果还有问题,就是 -lpython的问题,总之这个链接库我也没弄好,我是Linux下python2.7可以添加好,但是py文件搜索不到。3.5跟你这里一样,各种蛋疼,我估计是不是-lpython3。5这一步的问题。

16,213

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧