V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Mardo
V2EX  ›  Python

使用 python 调用 C++代码,但全局变量里有一个 map<string, double> m1,导致无法执行

  •  
  •   Mardo · 2015-12-12 22:17:59 +08:00 · 3012 次点击
    这是一个创建于 3061 天前的主题,其中的信息可能已经有所发展或是发生改变。

    rt ,现在有一个 c++写好的模块,代码里有好几个类似的 map<string, double> m1 是全局变量,当需要初始化这些的时候,就会报错 Segmentation fault 。使用的是如下封装代码。

    PyObject* wrap_loadFiles(PyObject* self, PyObject* args)
    {
    loadFiles();
    }

    static PyMethodDef keywordsExtraction[] =
    {
    {"loadFiles", wrap_loadFiles, METH_VARARGS ,"loadFiles"}
    };

    extern "C"

    void initkeywordsExtraction()
    {
    PyObject* m;
    m = Py_InitModule("keywordsExtraction", keywordsExtraction);
    }

    但是全局变量是 int 就没问题,是需要把 map<string, double>也封装么?我是 c++ python 菜鸟,跪求各位指点

    2 条回复    2015-12-12 22:36:01 +08:00
    fy
        1
    fy  
       2015-12-12 22:35:21 +08:00
    并没有 swig 有自带的几个封装文件…… 但说好用也有限
    zhuangzhuang1988
        2
    zhuangzhuang1988  
       2015-12-12 22:36:01 +08:00
    代码能否全一点..
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5453 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 06:48 · PVG 14:48 · LAX 23:48 · JFK 02:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.