0%

Python与boost::python相关文档

搭建基础环境

这里说明的是在Windows环境下的Visual Studio开发32位的pyd模块,并且Python、boost::python都是采用/MT(即使是在Debug构建模式下)的静态链接。

之所以在Debug构建模式也采用/MT,是因为boost::python模块的一些Assert在32位的Debug构建模式下会失败,目前发现的是与对齐相关的一些断言

安装Python 3.x

安装32位的Python并且把其安装目录添加到PATH环境变量中

安装meson

最好使用pip来安装meson,这样可以方便meson处理Python的依赖

1
pip install meson
阅读全文 »

以下是一个例子,关于custom_targetlink_depends的详细说明请看官方文档:

meson custom_target()

meson executable()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
FooBar_link_depends += custom_target(
'CopyBins',
output: ['foobar.dll'],
command: 'scripts/copy_folder.bat',
install: false,
env: {
'INPUT_DIR': bytertc_bin_root.replace('/', '\\'),
'OUTPUT_DIR': meson.current_build_dir().replace('/', '\\')
}
)

# ...

shared_library(
'FooBar',
[
FooBar_inc_files,
FooBar_src_files
],
include_directories: FooBar_inc,
link_depends: FooBar_link_depends,
)

Visual Studio C/C++解决方案的<项目名>[email protected]文件可以存储调试器的配置,可以利用configure_file,在meson执行configure时输出自定义的vcxproj.user文件。

meson configure_file()

这里以使用Python本机调试器为例子:

[email protected]文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='debug|Win32'">
<DebuggerFlavor>PythonDebugLaunchProvider</DebuggerFlavor>
<LocalDebuggerCommandArguments>-i -c "print('&gt;&gt;&gt; import FooBar'); import FooBar"</LocalDebuggerCommandArguments>
<LocalDebuggerCommand>@PYTHON_FULL_PATH@</LocalDebuggerCommand>
<LocalDebuggerWorkingDirectory>$(OutDirFullPath)</LocalDebuggerWorkingDirectory>
<LocalDebuggerEnvironment>PYTHONPATH=$(OutDirFullPath)</LocalDebuggerEnvironment>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='release|Win32'">
<DebuggerFlavor>PythonDebugLaunchProvider</DebuggerFlavor>
<LocalDebuggerCommandArguments>-i -c "print('&gt;&gt;&gt; import FooBar'); import FooBar"</LocalDebuggerCommandArguments>
<LocalDebuggerCommand>@PYTHON_FULL_PATH@</LocalDebuggerCommand>
<LocalDebuggerWorkingDirectory>$(OutDirFullPath)</LocalDebuggerWorkingDirectory>
<LocalDebuggerEnvironment>PYTHONPATH=$(OutDirFullPath)</LocalDebuggerEnvironment>
</PropertyGroup>
</Project>

上面的DebuggerFlavor也可以改为WindowsLocalDebugger

meson.build部分内容:

1
2
3
4
5
6
7
configure_file(
input: '@0@@sha.vcxproj.user.in'.format(meson.project_name()),
output: '@0@@sha.vcxproj.user'.format(meson.project_name()),
configuration : configuration_data({
'PYTHON_FULL_PATH': find_program('python').full_path()
})
)

Intel 32架构使用x86,64位使用x86_64

powershell

1
2
$Env:PROCESSOR_ARCHITEW6432 = 'x86'
meson setup build

cmd

1
2
set PROCESSOR_ARCHITEW6432=x86
meson setup build

bash

1
PROCESSOR_ARCHITEW6432=x86 meson setup build