funktioniert die einfachste Hallo Welt Beispiel Der Versuch von Boost Python Quick StartPython Erhöhung einfaches Beispiel nicht
#include <boost/python.hpp>
char const* greet()
{
return "hello, world";
}
BOOST_PYTHON_MODULE(hello_ext)
{
using namespace boost::python;
def("greet", greet);
}
Kompilieren Projekt unter Windows mit dem folgenden CMake:
cmake_minimum_required(VERSION 3.2)
project(hello_ext CXX)
set(TARGET hello_ext)
set(BOOST_MIN_VERSION "1.61.0")
set(Boost_ADDITIONAL_VERSIONS "1.61.0" "1.61")
set(BOOST_ROOT ${MY_BOOST_DIR})
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_STATIC_RUNTIME OFF)
set(Boost_USE_MULTITHREADED ON)
find_package(PythonLibs 3.4 REQUIRED)
find_package(Boost 1.61.0 COMPONENTS python REQUIRED)
file(GLOB SOURCES *.cpp)
include_directories(${INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS})
python_add_module(${TARGET} ${SOURCES})
target_link_libraries(${TARGET} ${Boost_PYTHON_LIBRARY} ${PYTHON_LIBRARIES})
Das Modul erfolgreich als hello_ext.pyd zusammengestellt. Der Versuch, darauf zuzugreifen aus dem Skript Python im selben Verzeichnis abgelegt ist:
import hello_ext
print(hello_ext.greet())
das folgende Ausführungser Anfahrt:
python3 test_cpp.py
Import Error: DLL load failed: The specified module could not be found
auch versucht, die hello_ext.pyd auf den Python DLL-Verzeichnis zu platzieren (C :/Python34/DLLs) mit dem gleichen Ergebnis
Windows 7 32-Bit-
C++ Compiler: Visual C++ 2015
.4.2 10Python Boost 1,61
Update: gelöst, siehe unten