V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · Dec 12, 2015 · 3903 views
    This topic created in 3802 days ago, the information mentioned may be changed or developed.

    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 replies    2015-12-12 22:36:01 +08:00
    fy
        1
    fy  
       Dec 12, 2015
    并没有 swig 有自带的几个封装文件…… 但说好用也有限
    zhuangzhuang1988
        2
    zhuangzhuang1988  
       Dec 12, 2015
    代码能否全一点..
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   874 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 21:38 · PVG 05:38 · LAX 14:38 · JFK 17:38
    ♥ Do have faith in what you're doing.