【发布时间】:2023-04-06 07:05:01
【问题描述】:
我有一个简单的 python 脚本,它使用带有ctypes 的 c/c++ 库。我的 c++ 库还包含一个 main 方法,因此我可以在没有 -shared 标志的情况下编译它,并且可以执行它并且运行没有问题。
但是,当我使用 ctypes 从 python 脚本运行相同的代码时,c++ 程序的一部分被执行(我可以从 cout 调用中看出这一点)。然后是整个应用程序,包括 python 脚本,termiantes(我可以从缺少的 cout 和 print 调用中看出这一点)。没有错误信息,没有段错误,没有python stacktrace。
我的问题是:我该如何调试它?发生这种情况的可能原因是什么?
这里是部分代码,不过,由于没有错误信息,所以不知道哪个代码是相关的。
import ctypes
interface = ctypes.CDLL("apprunner.so")
interface.start()
print "complete"
.
#include "../../app/ShaderApp.cpp"
#include <iostream>
#include "TestApp.cpp"
TestApp* app = 0;
extern "C" void start() {
app = new TestApp();
cout << "Running from library" << endl;
app->run();
}
int main( int argc, const char* argv[]) {
cout << "Running from excecutable" << endl;
start();
}
【问题讨论】: