C++库与Shiboken的python绑定生成

问题描述:

我在wiki上按照教程向上http://qt-project.org/wiki/PySide_Binding_Generation_Tutorial 但我无法让它正常工作。我MacOSX上C++库与Shiboken的python绑定生成

到目前为止,这是我做的:

  • 建立FooLib(静态)---> libFooLib.a
  • 创建typesystem_foo.xml
  • 运行与shiboken以下命令:

    shiboken-2.7 global.h --include-paths =。/ opt/local/include/PySide-2.7:/ opt/local/include --typesystem-paths =/opt/local/share /PySide-2.7/typesystems --output-directory = ../FooLibBinding typesystem_foo.xml

  • 构建FooLibBinding动态库从导致生成C++代码 - > libFooLibBinding.dylib

现在,而不是只在命令行运行python解释,我由C++程序这将加载python解释器并使用FooLib打开一个.py脚本。这个程序对动态链接libFooLibBinding.dylib所以我想工作是否有所需foolib模块的所有符号;)

下面的代码:

#include <iostream> 
#include <Python.h> 

int main(int argc, char* argv[]) 
{ 

    ///Python init 
    Py_SetProgramName(argv[0]); 
    Py_Initialize(); 
    PySys_SetArgv(argc, argv); /// relative module import 

    ///Try out loading the module, this is just for testing 
    /// ----------- 
    PyObject *sysPath = PySys_GetObject("path"); 
    PyObject *path = PyString_FromString("/Users/alexandre/Downloads/BindingTest"); 
    int result = PyList_Insert(sysPath, 0, path); 
    PyObject *pModule = PyImport_ImportModule("foolib"); 
    if (PyErr_Occurred()) 
      PyErr_Print(); 
    /// ----------- 

    ///Our python file to interpret 
    const char* filename = "/Users/alexandre/Downloads/BindingTest/FooLibTest/foolib_test.py"; 
    FILE* file = fopen(filename,"r"); 
    PyRun_SimpleFile(file,filename); 

    ///close python 
    Py_Finalize(); 
    return 0; 
} 

运行程序时,它试图失败时运行的.py脚本时没有名为foolib

模块,然后第二次:

Traceback (most recent call last): 
    File "/Users/alexandre/Downloads/BindingTest/FooLibTest/foolib_test.py", line 1, in <module> 
    from foolib import FooClass 
ImportError: No module named foolib 
加载模块的第一时间说: 导入错误

显然,它无法找到从绑定生成的模块。我的问题是我该怎么做才能找到它?

本教程使用了一个Makefile,但似乎不仅仅是链接绑定动态库。

Shiboken命令行的包含路径不包含foo.h的路径。我不知道如果这是你的问题的原因,但如果我做了同样的,也不会生成以下文件:

  • math_wrapper.cpp
  • math_wrapper.h

......你显然需要能够编译对foo库中Maths类的支持。