mquasar
mquasar

Reputation: 161

pybind with third-party C++ on Windows (ImportError: DLL load failed)

I'm trying to use a third-party c++ lib from python using pybind11.

I have managed to do it using pure C++ code, but, when I add the third-party code I get the following error:

ImportError: DLL load failed while importing recfusionbind

Here's my code:

#include <RecFusion.h>
#include <pybind11/pybind11.h>

using namespace RecFusion;

bool isValidLicense() {
    return RecFusionSDK::setLicenseFile("License.dat");
}

namespace py = pybind11;

PYBIND11_MODULE(recfusionbind, m) {
    m.def("isValidLicense", &isValidLicense, R"pbdoc(
        Check if there is a valid license file.
    )pbdoc");

#ifdef VERSION_INFO
    m.attr("__version__") = VERSION_INFO;
#else
    m.attr("__version__") = "dev";
#endif
}

If i change, for testing purposes, the return of the function to simply true it works just fine. But calling the third-party library gives the above mentioned error. I have put RecFusion.dll on the current directory (where the python script is), with same results.

Any tips on what I'm missing will be welcomed. Lib is 64 bits, same as my code.

Upvotes: 1

Views: 883

Answers (1)

unddoch
unddoch

Reputation: 6004

This seems to me like a linking problem. Look at your dll's import table (with tools like PE explorer or IDA). Now validate that the function RecFusionSDK::setLicenseFile is indeed imported from a dll named RecFusion.dll and not some other dll name.

Also validate that the mangled function name in RecFusion.dll's export table and in your dll match. If not, this could be an ABI problem.

Upvotes: 2

Related Questions