说明
- 操作系统: debian12
- 安装apt install gcc
- 安装 apt install python3 -dev
- 安装 apt install g++
配置vscode远程
- 安装ssh-development
- 配置 .ssh文件
Host 192.168.225.111
HostName 192.168.225.111
User rc
IdentityFile E:\vm_debian\rc_rsa
- 报错信息:
- 1.It is required that your private key files are NOT accessible by others
- 比较麻烦,暂时还没有找打比较好的方法,先暂时使用密码登录方便,后续有空了再研究
- 参考链接: https://zhuanlan.zhihu.com/p/97706106
程序设计实现
- 编译脚本
- g++ -o bubble bubble.cpp -I /usr/include/python3.11 -l python3.11 不能使用gdb调试
- g++ -g bubble.cpp -o bubble -I /usr/include/python3.11 -l python3.11 可以使用gdb调试
- -g 参数可以gcc在编译是会做以下额外的操作:
- 创建符号表,符号表包含了程序中使用的变量名称的列表
- 关闭所有的优化机制,以便程序执行过程中严格按照原来的C代码进行
c++ 执行python的脚本
- 参考链接:https://zhuanlan.zhihu.com/p/79896193
#include <Python.h>
int main() {
Py_Initialize();
PyRun_SimpleString("import sys");
PyRun_SimpleString("print('hello world')");
Py_Finalize();
return 0;
}
#include <Python.h>
#include <iostream>
using namespace std;
int main() {
Py_Initialize();
if (!Py_IsInitialized())
{
cout << "Python init fail" << endl;
return -1;
}
cout << "Python init ok" << endl;
PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append('./')");
PyObject* pModule = PyImport_ImportModule("bubble_sort");
if (pModule == NULL)
{
cout << "PyImport_ImportModule fail" << endl;
return -1;
}
PyObject* pFunc = PyObject_GetAttrString(pModule, "say_hello");
if (!pFunc || !PyCallable_Check(pFunc))
{
cout << "not found function say_hello" << endl;
return -1;
}
PyObject_CallObject(pFunc, NULL);
Py_Finalize();
return 0;
}
#include <Python.h>
#include <iostream>
using namespace std;
int main() {
Py_Initialize();
if (!Py_IsInitialized())
{
cout << "Python init fail" << endl;
return -1;
}
cout << "Python init ok" << endl;
PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append('./')");
PyObject* pModule = PyImport_ImportModule("bubble_sort");
if (pModule == NULL)
{
cout << "PyImport_ImportModule fail" << endl;
return -1;
}
PyObject* pFunc = PyObject_GetAttrString(pModule, "bubble_sort");
if (!pFunc || !PyCallable_Check(pFunc))
{
cout << "not found function bubble_sort" << endl;
return -1;
}
PyObject* pArgs = PyList_New(0);
PyList_Append(pArgs, Py_BuildValue("i", 10));
PyList_Append(pArgs, Py_BuildValue("i", 99));
PyList_Append(pArgs, Py_BuildValue("i", 8));
PyList_Append(pArgs, Py_BuildValue("i", 71));
PyList_Append(pArgs, Py_BuildValue("i", 6));
PyList_Append(pArgs, Py_BuildValue("i", 53