C ++ Boost Python методы из библиотеки * .pyd не работают - PullRequest
0 голосов
/ 06 февраля 2019

Добрый день, у меня есть несколько проблем с простыми примерами из boost :: python - Все методы, которые должны возвращать любые типы, кроме char const* или создавать классы, ничего не возвращают и все, что я вижу, это RESTART: Shell.

Я использую:

  • CLion 2018.3.3, сборка № CL-183.5153.40, построена 10 января 2019 года;
  • MinGW-w64 \x86_64-8.1.0-SEH-POSIX-rt_v6-rev0;
  • CMake 3.13.0-rc1 -;
  • Python 3.7 (x86_64);
  • boost 1.68.0,

, который был построен сследующие аргументы:

bootstrap gcc 
b2 -j12 toolset=gcc runtime-link=shared architecture=x86 address-model=64 --with-python cxxflags="-D__int64=\"long long int\" -DBOOST_REGEX_MATCH_EXTRA -D__NO_INLINE__ -D_hypot=hypot"  --build-type=complete --layout=tagged stage

CMakeList.txt содержит:

cmake_minimum_required(VERSION 3.13)
project(pylibtest)

set(CMAKE_CXX_STANDARD 17)

set(GCC_COVERAGE_COMPILE_FLAGS "-march=native  -m64 -D_hypot=hypot -static -static-libstdc++ -static-libgcc -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}" )

message(STATUS "start running cmake...")

set(Boost_DEBUG                 OFF)
#set(Boost_USE_STATIC_LIBS       ON)
set(Boost_USE_MULTITHREADED     ON)
#set(Boost_USE_STATIC_RUNTIME    ON)

find_package(Boost 1.68.0 COMPONENTS python37 REQUIRED)
if(NOT Boost_FOUND)
    set(Boost_LIBRARY_DIR "${Boost_Path}/stage/lib")
    message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARY_DIR}")
    message(STATUS "Boost_VERSION: ${Boost_VERSION}")
    include_directories(${Boost_INCLUDE_DIRS})
    link_directories(${Boost_LIBRARIES})
endif()

find_package(PythonInterp 3.7 REQUIRED)
find_package(PythonLibs 3.7 REQUIRED)
if(PYTHONLIBS_FOUND)
    message(STATUS "PYTHON_LIBRARIES = ${PYTHON_LIBRARIES}")
    message(STATUS "PYTHON_EXECUTABLE = ${PYTHON_EXECUTABLE}")
    message(STATUS "PYTHON_INCLUDE_DIRS = ${PYTHON_INCLUDE_DIRS}")
    include_directories(${PYTHON_INCLUDE_DIRS})
    link_directories(${PYTHON_LIBRARIES})
endif()

if(Boost_FOUND AND PYTHONLIBS_FOUND)
    add_library(pylibtest SHARED library.cpp library.h wrap.cpp Some.cpp Some.h)
    target_include_directories(pylibtest SYSTEM PRIVATE  ${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS})
    target_link_libraries(pylibtest ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
endif()

wrap.cpp, который содержит все методы и их определения в модуле python:

#include <boost/python.hpp>
//#include "Some.h"

using namespace boost::python;

char const* SayHello()
{
    return "Hello, from c++ dll!";
}

int GetMeNumber(){
    int temp = 255;
    return temp;
}

BOOST_PYTHON_MODULE( example )
{
    def("SayHello", SayHello);
    def("GetMeNumber", GetMeNumber);
}

Скрипт Python в IDLE 3.7 (64-битный):

print("Procedure started:")
import example
print(example.SayHello())
print("Procudure ended")
print("-=-=-=-=-=-=-=-=-=-=-=-")
print("New procedure started")
count = example.GetMeNumber();
print(count)
print("New procudure ended")

и выход в оболочке Python 3.7.0:

Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 
===== RESTART: C:\..\pi.py =====
Procedure started:
Hello, from c++ dll!
Procudure ended
-=-=-=-=-=-=-=-=-=-=-=-
New procedure started

=============================== RESTART: Shell ===============================
>>> 

Когда я пытался использовать тот же скрипт в PyCharm Iвышло сообщение с кодом ошибки:

Procedure started:
Hello, from c++ dll!
Procudure ended
-=-=-=-=-=-=-=-=-=-=-=-
New procedure started

Process finished with exit code -1073741819 (0xC0000005)

Кто-нибудь знает, что не так с моей библиотекой и как лучше ее заработать?

1 Ответ

0 голосов
/ 06 февраля 2019

Код 0xC0000005 равен Access Violation.Вы можете попытаться повторить все под учетной записью администратора.

...