John Laughlin
John Laughlin

Reputation: 57

Boost.Python and importing a dll, "The specified module could not be found"

Software info up front:

MSVC 2008/9.0 (my company has a hard time letting go)

Boost 1.64

Python 2.7 (a really hard time letting go)

We're converting a DLL module for one of our programs to be able to run Python scripts that can interface back with the module, so I've been wiring up Boost.Python. I made a very simple example following the tutorial:

using namespace boost::python;

BOOST_PYTHON_MODULE(PythonModule)
{
    class_<CPythonModule, boost::noncopyable>("PythonModule")
        .def("foo", &CPythonModule::foo)
        ;
}

(Edit: my use of noncopyable here could be incorrect; we have an instance of an object that will be running the python scripts, and this was needed to compile to eliminate private function errors)

And the even simpler Python script that doesn't even do anything but import for now:

import PythonModule

Everything compiled, ran the script... Import failure. Learned I had to switch the DLL file extension to .pyd, and ran it again, hit a slightly different error:

ImportError: DLL load failed: The specified module could not be found.

I can't manage to make this one go away. I have included the boost DLLs in the running directory alongside the scripts, no dice. From what I can see, it is actually finding the .pyd, but something else is going wrong after that. Things I've made sure of:

C++ 'Additional Include' includes paths to "python27\includes" and "boost_1_64_0".

Linker 'Additional Library' directories includes paths to "Python27\libs" and "boost_1_64_0\lib32-msvc-9.0".

Somewhere along the way in trying to eliminate the error as I went through SO posts, I also went ahead and tried adding these to the Linker's additional dependencies:

C:\local\boost_1_64_0\lib32-msvc-9.0\boost_python-vc90-mt-1_64.lib
C:\local\boost_1_64_0\lib32-msvc-9.0\boost_python-vc90-mt-gd-1_64.lib
C:\local\boost_1_64_0\lib32-msvc-9.0\libboost_python-vc90-mt-1_64.lib
C:\local\boost_1_64_0\lib32-msvc-9.0\libboost_python-vc90-mt-gd-1_64.lib

My environment paths also include Boost, Python, and even the specific directory I've tried running the script from.

Upvotes: 0

Views: 2525

Answers (1)

doqtor
doqtor

Reputation: 8484

Make sure that the name provided into BOOST_PYTHON_MODULE() matches the binary name. So for BOOST_PYTHON_MODULE(PythonModule) the binary name should be PythonModule.pyd. Also place binary module and test script in the same folder.

If that doesn't work then use Process Monitor and Dependency Walker to figure out what's going on. For example there may be a conflict with other python dll installed in your system which appears on the PATH earlier than the version you are expecting to use. Or for some reason a python dll or any other required dll can't be loaded. And so on. This can be really anything and you need to investigate it yourself.

Upvotes: 4

Related Questions