我需要为现有的C ++模块编写一个python包装器。首先,我使用这个基本示例测试了该过程(现在实际上工作正常):C++ - Python Binding with ctypes - Return multiple values in function
现在我尝试更改设置:我想使用现有的lib而不是我的单个cpp文件。我试着这样做了:
g++ -c -I. -fPIC projectionWrapper.cpp -o projectionWrapper.o
g++ -shared -Wl,-soname,libproj.so
-L./build/liborig_interface.a,./build/liborig_base.a
-o libproj.so projectionWrapper.o
我想用-L命令链接来自给定库的两个.a文件。我没有收到任何错误,但当我尝试通过ipython导入模块时,我得到了这个:
import myprojection # I load libproj.so in this python file
OSError: ./libproj.so: undefined symbol: _Z29calibration_loadPKcjbP14camera_typetS2_
有一个功能" calibration_load"以及" camera_type"在原始框架中。但我不知道两者之间的神秘事物来自哪里。
对不起我的模糊解释,我试图尽可能好地解释它,但是C ++ Wrapper不是我感觉到的主题之一"在家里"。
答案 0 :(得分:1)
The problem is that you're not linking against the external library that you use in your C++ code; add -l<library>
to your second g++
call.
答案 1 :(得分:0)
beforeInitData
完成了这项工作。感谢您提示我实际上没有链接库,因为我只使用-L选项。
此外,选项的顺序是错误的。我必须在开头说“projectionWrapper.o”,在“-lorigbase”之前说“-loriginterface”。这回答了这里:"undefined reference" when linking against a static library
(libs的完整名称是:liboriginterface.a和liborigbase.a)