我需要在C++中调用Python函数。
Python:
import tkinter as tk
class GUI:
def __init__(self):
self.root=tk.Tk()
def run(self):
self.root.mainloop()
C++:(此时Python以编译成pyd,名曰:main.pyd)
#include <iostream>
#pragma comment(lib,"python310.lib")
#pragma comment(lib,"python3.lib")
#pragma comment(dll,"python3.dll")
#pragma comment(dll,"python310.dll")
#pragma comment(zip,"base_library.zip")
#pragma comment(pyd,"main.pyd")
using namespace std;
int main()
{
GUI a;
a.run()
}
但是它报错了:
未命名1.cpp: In function 'int main()':
未命名1.cpp:11:2: error: 'GUI' was not declared in this scope
GUI a;
^
未命名1.cpp:12:2: error: 'a' was not declared in this scope
a.run()
^
编译结果:
- 错误: 2
- 警告: 0
- 输出文件名: 未命名1.exe
- 输出大小:
- 编译时间: 0.14s
我不知道应该怎么做。
我希望调用成功,大家能帮帮我吗?