python37使用其他版本版本pyd,python - * .pyd库中的C ++ Boost Python方法不起作用 - 堆栈内存溢出...

美好的一天,我遇到了来自boost :: python的简单示例的一些问题-所有必须返回除char const*以外的任何类型或创建Classes的方法均不返回任何内容,而我所看到的一切都是RESTART: Shell 。

我正在使用:

CLion 2018.3.3,内部版本#CL-183.5153.40,建于2019年1月10日;

MinGW的-W64 \\ x86_64-8.1.0-POSIX的SEH-rt_v6-REV0;

CMake 3.13.0-rc1-;

Python 3.7(x86_64);

提升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

//#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);

}

IDLE 3.7(64位)中的Python脚本:

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 Shell中的内容:

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中使用相同的脚本时,出现了错误代码消息:

Procedure started:

Hello, from c++ dll!

Procudure ended

-=-=-=-=-=-=-=-=-=-=-=-

New procedure started

Process finished with exit code -1073741819 (0xC0000005)

有谁知道我的lib库出了什么问题,什么是更好的工作方法?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值