带有 boost 的 Python 的 C++ 扩展不起作用
c++ extension for python with boost doesn't works
我有一个小的 c++ 模块:(这段代码很糟糕,但它只是原型)
librecv.cpp:
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/containers/vector.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <string>
#include <stdio.h>
#include <cstdlib>
typedef boost::interprocess::allocator<float, boost::interprocess::managed_shared_memory::segment_manager> ShmemAllocator;
typedef boost::interprocess::vector<float, ShmemAllocator> DataVector;
void _init()
{
printf("Initialization of shared objectn");
}
void _fini()
{
printf("Clean-up of shared objectn");
}
void work()
{
boost::interprocess::managed_shared_memory segment(boost::interprocess::open_only, "MySharedMemory");
DataVector *myvector = segment.find<DataVector>("MyVector").first;
for(int i = 0; i < 100; ++i) //Insert data in the vector
{
printf("%f ", (float)myvector->at(i));
}
};
我想在我的 python 代码中使用函数"work"我尝试编译C++库:(我可能会错过这里的东西吗?
g++ -fPIC -c librecv.cpp -lboost_system -lrt
g++ -shared -o libtest.so.1.0 -lc librecv.o
蟒蛇代码:
from ctypes import *
libtest = cdll.LoadLibrary('./libtest.so.1.0') #python should call function "_init" here, but nothing happens
libtest.work
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/ctypes/__init__.py", line 378, in __getattr__
func = self.__getitem__(name)
File "/usr/lib/python2.7/ctypes/__init__.py", line 383, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: ./libtest.so.1.0: undefined symbol: work
操作系统:乌班图有出路吗?PS对不起我的写作错误。英语不是我的母语
C++混淆名称(函数,类,结构,联合等)(见这里)。
您可以通过运行以下命令找到共享对象中实际导出的名称:
/usr/bin/nm libtest.so.1.0
在您的情况下,work()
函数可能正在被破坏以_Z4workv()
。
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- C++为什么尽管我调用了void函数,它却不起作用
- 为什么在保护模式下继承升级不起作用
- 循环在计数器中不起作用
- 在其他文件中创建类时在 c++ 项目中不起作用
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 文件写入在PHP扩展c / c ++(linux)中不起作用
- Microsoft具有本机消息传递和非持久连接的边缘扩展不起作用
- 参数包扩展不起作用
- 我的火狐扩展程序不起作用。使用C++XPCOM组件的Firefox扩展(XPI文件)的结构是什么?
- QML 简单扩展不起作用
- 基于文件扩展名的筛选在QFileSystemModel中不起作用
- 内联扩展可能不起作用的情况
- ContextMenu项扩展在Windows 7中不起作用
- 正则表达式替换文件扩展名前缀放置不起作用 - 替换匹配项
- 带有 boost 的 Python 的 C++ 扩展不起作用
- Firefox XPCOM 扩展在安装后不起作用 (C++)
- Rename()函数在尝试向文件添加扩展名时不起作用