C++中用Boost::Python调用Python模块

这个过程有挺多坑,记录一下。我这里的环境:

Windows 11

Qt 6.2

Boost 1.8.4

CMake 3.25.2

Visual Stutio 2019(主要用于C++编译)

1、下载并将Boost编译为静态库

b2.exe toolset=msvc-14.2 install --prefix=boost安装路径 link=static

参考:

C++ Boost库在windows下的安装与使用 - 知乎 (zhihu.com)

2、CMake中使用静态库

set(Boost_USE_STATIC_LIBS ON) add_compile_definitions(BOOST_PYTHON_STATIC_LIB)

参考:

Win10下CMakeList.txt配置使用Boost.python - 知乎 (zhihu.com)

3、Python程序

如下(foo.py):

def greeting(s):
    print("Get the param in Python: ", s, " \n")
    return "Hello, I come from Pyhon world."
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值