Skip to content

[features] ImportError: DLL load failed with pybind11 and PCL #3963

Open
@adishavit

Description

@adishavit

I'm using pybind11 to create a Python wrapper for a small C++ class.
I'm getting the following error when importing the DLL (running python -v to show Traceback):

>>> from a_py import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 657, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 556, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1101, in create_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: DLL load failed while importing a_py: The specified module could not be found.

The class has just two members - types from the PCL library:

class A
{
   pcl::NormalEstimation< pcl::PointXYZ, pcl::Normal> normalEstimation_;
   pcl::PointCloud<pcl::Normal>::Ptr normals_;
};

If I remove the first member I can successfully import the module from the DLL.

This is the pybind11 code:

namespace py = pybind11;

PYBIND11_MODULE(a_py, m)
{
   py::class_<A>(m, "A");
}

PCL is found using CMake: find_package(PCL REQUIRED)

This happens on both Windows and Linux with the latest PCL (1.10) and older versions too.

(Adding #define PCL_NO_PRECOMPILE before the #includes does not help.)
[also posted on SO]

Your Environment (please complete the following information):

  • OS: Windows 10 (but similar issues on Linux)
  • Compiler: MSVC 2019
  • PCL Version1.10.0

Possible Solution

Based on a SO suggestion I ran the Dependencies app on both DLLs (with and without the offending line).
The main difference was that the offending DLL depends on c:\Program Files\PCL 1.10.0\bin\pcl_common.dll. Strangely enough, it seems to only rely on one function: void __cdecl pcl::console::print(enum pcl::console::VERBOSITY_LEVEL,char const * __ptr64,...).
AFAICT, PCL is mostly header only, and somewhere within the guts of pcl::NormalEstimation there is a logging function which is not header-only and needs linking. Is there a way to prevent this call?

BTW, the DLL is in the DLL paths (and as can be seen in the screenshot - available) so it is still unclear why Python fails to load the module.

image

Additional context

Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions