I am trying to compile a pcl-included c++ function into a shared library using g++(Of course, I can use cmake but I found results not changing).
The test code is quite simple:
#include <iostream>
#include <pcl/ModelCoefficients.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/sample_consensus/method_types.h>
#include <pcl/sample_consensus/model_types.h>
#include <pcl/segmentation/sac_segmentation.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/filters/extract_indices.h>
extern "C" int add_one(int i)
{
// pcl::PCLPointCloud2::Ptr cloud_blob (new pcl::PCLPointCloud2), cloud_filtered_blob (new pcl::PCLPointCloud2);
return i+1;
}
int main()
{
return 0;
}
The g++ compilation command is:
g++ -shared -L/usr/lib/x86_64-linux-gnu/ -I/usr/include/pcl-1.7 -I/usr/include/eigen3 -o testlib.so -fPIC extract_indices.cpp
I can successfully compile it. I write a Python wrapper as :
import sys
import os
from ctypes import cdll
lib = cdll.LoadLibrary('./testlib.so')
print lib.add_one(5)
When I run this, it shows :
Traceback (most recent call last):
File "test.py", line 4, in <module>
lib = cdll.LoadLibrary('./testlib.so')
File "/home/weizhang/anaconda2/lib/python2.7/ctypes/__init__.py", line 444, in LoadLibrary
return self._dlltype(name)
File "/home/weizhang/anaconda2/lib/python2.7/ctypes/__init__.py", line 366, in __init__
self._handle = _dlopen(self._name, mode)
OSError: ./testlib.so: undefined symbol: _ZN5boost6system15system_categoryEv
After a little debugging, I found out #include <pcl/io/pcd_io.h>
this line is the one causing the problem. Any other inclusion is fine.
I have no clue of why that happens.
Any idea is helpful and appreciated!