感谢对仓颉社区的支持与关注,欢迎反馈缺陷。 | Thanks for your support and attention to the community. We welcome feedback on any issues.
Tools
Windows 上通过 foreign + [ffi.c] 使用 C 动态库时,构建期与运行期的 dll 查找行为不一致,且失败模式完全静默:
foreign
[ffi.c]
libs/libdanqing.dll
lib
danqing.dll
0xC0000135 (STATUS_DLL_NOT_FOUND)
target\release\bin\
libdanqing.dll
实际排查经历:最初现象是"运行时负退出码、无任何错误信息",需要用 dumpbin /dependents 查 import 表才能定位到缺失 dll,对新人非常不友好。
dumpbin /dependents
cjpm build
cjpm run
libs/lib<name>.dll
<name>.dll
0xC0000135
更完整的实践记录(含两条路径的解决方案对比): https://gitcode.com/m0_74475107/Danqing(CHANGELOG 与 docs/)
附带一个同属 cjpm 的文档问题:[package].organization 字段一旦填写, 会要求源码 package 声明同步改为 <org>::<name>(构建报错 "the package name in ... is wrong, the right name should be 'org::name'"), 文档未前置说明该语义,建议一并澄清。
[package].organization
<org>::<name>
Cangjie Compiler: 1.1.3 (cjnative) Target: x86_64-w64-mingw32
感谢对仓颉社区的支持与关注,欢迎反馈缺陷。 | Thanks for your support and attention to the community. We welcome feedback on any issues.
领域 | Domain
Tools
发生了什么问题? | Describe the issue that occurred.
Windows 上通过
foreign+[ffi.c]使用 C 动态库时,构建期与运行期的dll 查找行为不一致,且失败模式完全静默:
libs/libdanqing.dll(lib前缀)——没有它构建直接失败("can not find the library 'danqing'");
danqing.dll(无前缀)——即便构建成功,若该文件不在 exe 旁边,进程以
0xC0000135 (STATUS_DLL_NOT_FOUND)退出;target\release\bin\——开发者必须手工把两份文件(
danqing.dll与libdanqing.dll)都放到输出目录。实际排查经历:最初现象是"运行时负退出码、无任何错误信息",需要用
dumpbin /dependents查 import 表才能定位到缺失 dll,对新人非常不友好。期望行为是什么? | What is the expected behavior?
cjpm build后自动将[ffi.c]依赖的 dll 复制到输出目录(可参照Cargo 的构建脚本链接模式);
cjpm run时做一层依赖 dll 存在性检查,给出可读诊断而非静默的加载器失败;
lib前缀命名 vs 运行期裸名"的差异。如何复现该缺陷? | How to reproduce the bug?
foreign调用 +[ffi.c]声明动态库依赖的工程;libs/lib<name>.dll存在 →cjpm build成功;<name>.dll从target\release\bin\移走 → 运行 exe:进程以
0xC0000135退出,无任何提示。更完整的实践记录(含两条路径的解决方案对比):
https://gitcode.com/m0_74475107/Danqing(CHANGELOG 与 docs/)
其他补充信息 | Additional information
附带一个同属 cjpm 的文档问题:
[package].organization字段一旦填写,会要求源码 package 声明同步改为
<org>::<name>(构建报错"the package name in ... is wrong, the right name should be 'org::name'"),
文档未前置说明该语义,建议一并澄清。
cjc版本信息 | cjc version information
Cangjie Compiler: 1.1.3 (cjnative)
Target: x86_64-w64-mingw32
分支版本信息 | Branch version information