Skip to content

支持 macOS 下使用 OpenCTP dylib 构建#14

Open
Yong-yuan-X wants to merge 1 commit into
ctpbee:masterfrom
Yong-yuan-X:fix-macos-openctp-dylib
Open

支持 macOS 下使用 OpenCTP dylib 构建#14
Yong-yuan-X wants to merge 1 commit into
ctpbee:masterfrom
Yong-yuan-X:fix-macos-openctp-dylib

Conversation

@Yong-yuan-X
Copy link
Copy Markdown

关联 issue: ctpbee/ctpbee#325

我在 macOS 本地复现了一下,当前 ctpbee_api 在 macOS 下编译生成的 vnctpmd / vnctptd 默认链接到 ~/.ctpbee/Frameworks 下的 framework:

@rpath/thosttraderapi_se.framework/thosttraderapi_se
@rpath/thostmduserapi_se.framework/thostmduserapi_se

因此,即使把 OpenCTP 的 .dylib 文件复制到 ctpbee_api/ctp 目录,现有构建产物也不会加载这些 dylib。

本 PR 增加了一个可选环境变量:

CTPBEE_CTP_DYLIB_DIR=/path/to/openctp/lib

当该环境变量存在时,macOS 构建会使用该目录下的 OpenCTP dylib,并将 dylib 复制到 ctpbee_api/ctp 包目录中,保证运行时可以通过 @loader_path 正确加载。目前兼容以下文件名:

libthosttraderapi_se.dylib / thosttraderapi_se.dylib
libthostmduserapi_se.dylib / thostmduserapi_se.dylib

如果没有设置 CTPBEE_CTP_DYLIB_DIR,则保持原有 framework 构建逻辑不变。

我使用 PyPI 上的 openctp-ctp wheel 解压出的 dylib 进行了验证:

CTPBEE_CTP_DYLIB_DIR=/Users/a1-6/Downloads/openctp-wheel/unpacked/openctp_ctp \
  python -m pip install -e .

安装后执行:

python -c "from ctpbee_api.ctp import MdApi, TdApi; print(MdApi, TdApi)"

可以正常导入:

<class 'ctpbee_api.ctp.vnctpmd.MdApi'> <class 'ctpbee_api.ctp.vnctptd.TdApi'>

otool -L 输出变为:

@loader_path/libthosttraderapi_se.dylib
@loader_path/libthostmduserapi_se.dylib

说明构建产物已经从 framework 链接切换到 OpenCTP dylib。

@somewheve
Copy link
Copy Markdown
Member

不好意思 没有看到此 问下你这个在三个系统下是否都能构建成功

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants