1

Recently I have been trying to get some Point Cloud Library functionality going in my .NET framework application, and considering that there is no completely functional wrapper for PCL for C#, I made my own for a few functions as a test. Something like this:

[DllImport(DllFilePath, CallingConvention = CallingConvention.Cdecl)]
public extern static IntPtr StatisticalOutlierFilter(IntPtr data, int length, int meanK = 50, float mulThresh = 1.0f);

Which calls a function from a C++ library, such as this:

EXPORT VectorXYZ* StatisticalOutlierFilter(VectorXYZ* data, int length, int meanK, float mulThresh) {

    auto processedCloud = process.StatisticalOutlierFilter(data, length, meanK, mulThresh);
    auto processedVector = convert.ToVectorXYZ(processedCloud);

    return processedVector;
}

Where EXPORT is defined such for gcc:

#define EXPORT extern "C" __attribute__ ((visibility ("default")))

And relevant processing function from PCL is implemented such in a class (note that the returned is a boost shared pointer):

PointCloud<PointXYZ>::Ptr Processors::StatisticalOutlierFilter(VectorXYZ* data, int length, int meanK, float mulThresh) {

    auto cloud = PrepareCloud(data, length);
    PointCloud<PointXYZ>::Ptr cloud_filtered(new PointCloud<PointXYZ>);

    StatisticalOutlierRemoval<PointXYZ> sor;
    sor.setInputCloud(cloud);
    sor.setMeanK(meanK);
    sor.setStddevMulThresh(mulThresh);
    sor.filter(*cloud_filtered);

    return cloud_filtered;
}

This procedure works well with a dll built w/MSVC and running the whole thing on Windows, though the final target is gcc/Linux/Mono, where I get several errors of the following type (this is from mono debug):

'libavpcl_dll.so': '/usr/lib/libavpcl_dll.so: undefined symbol: _ZN3pcl7PCLBaseINS_8PointXYZEE13setInputCloudERKN5boost10shared_ptrIKNS_10PointCloudIS1_EEEE'.

I have investigated quite a bit so far, and have set my CmakeLists.txt to set(CMAKE_CXX_VISIBILITY_PRESET hidden) , therefore, I imagine, only functions I defined as EXPORT should be visible and imported - however, that is not the case, and I get the aforementioned errors. PCL was installed on Windows via vcpkg and on Xubuntu via apt. I am somewhat stumped as to what is the error source, considering the code runs well on windows, and builds without issue on Linux. Thanks.

xen20
  • 61
  • 2
  • 10

1 Answers1

0

I've been running into the same issue as you. I solved it by adding each reference library into the CMakeLists.txt file (I was missing the reference files which gave me the similar missing symbol issues).

I'm at the 'I don't know why this worked' stage but I can give you step by step implementation (I'm also trying to use DllImport into .NET on Linux).

Started with this: https://medium.com/@xaviergeerinck/how-to-bind-c-code-with-dotnet-core-157a121c0aa6

Then added my in-scope files thanks to the main comment here: How to create a shared library with cmake?:

add_library(mylib SHARED
    sources/animation.cpp
    sources/buffers.cpp
    [...]
)
  • run cmake .
  • run make -j$(grep -c ^processor /proc/cpuinfo)
  • copy path to .so file
  • DllImport path from above to my c# app
Emilie
  • 71
  • 4