我在为 C 库 zbar 编写 Julia 的封装器,通过 Build_tarball 脚本 构建了 JLL 包,products
有两个内容:
...
products = [
LibraryProduct("libzbar", :libzbar),
ExecutableProduct("zbarimg", :zbarimg),
]
通过 run
可以将 zbarimg
简单地封装为 Julia 函数。
Q1:
libzbar
中的函数怎么用 Clang 自动封装?
我尝试了 Clang 文档写的 generator.toml
和 generator.jl
# generator.toml
[general]
library_name = "libzbar"
output_file_path = "./Libzbar.jl"
module_name = "Libzbar"
jll_pkg_name = "zbar_jll"
# generator.jl
using Clang.Generators
using zbar_jll
cd(@__DIR__)
include_dir = normpath(zbar_jll.artifact_dir, "include")
# wrapper generator options
options = load_options(joinpath(@__DIR__, "generator.toml"))
# add compiler flags, e.g. "-DXXXXXXXXX"
args = get_default_args()
push!(args, "-I$include_dir")
# only wrap libclang headers in include/zbar
header_dir = joinpath(include_dir, "zbar")
headers = [joinpath(header_dir, header) for header in readdir(header_dir) if endswith(header, ".h")]
# create context
ctx = create_context(headers, args, options)
# run generator
build!(ctx)
但执行命令 julia --project generator.jl
后只得到了空白的 Libzbar.jl
module Libzbar
using zbar_jll
export zbar_jll
using CEnum
end # module
执行过程存在警告 error: "include zbar.h in your application, **not** zbar/Decoder.h"
[ Info: Parsing headers...
/home/rex/.julia/artifacts/ae0ec45fea87ed0c66d1c51f18e96ffa0deedb2c/include/zbar/Decoder.h:30:3: error: "include zbar.h in your application, **not** zbar/Decoder.h"
Q2:
generator
文件应该怎么修改 ?
附:zbar 的头文件路径
include/
├── config.h
├── config.h.in
├── Makefile.am.inc
├── stamp-h1
├── zbar
│ ├── Decoder.h
│ ├── Exception.h
│ ├── Image.h
│ ├── ImageScanner.h
│ ├── Processor.h
│ ├── QZBar.h
│ ├── QZBarImage.h
│ ├── Scanner.h
│ ├── Symbol.h
│ ├── Video.h
│ ├── Window.h
│ └── zbargtk.h
└── zbar.h
另外,在 ./configure
构建时,我没有启用所有参数,而只指定了 zbarimg
```bash
=> zbarcam video scanner will *NOT* be built
=> libv4l will *NOT* be used
=> JPEG image conversions will *NOT* be supported
=> GTK support will *NOT* be built
=> the Qt widget will *NOT* be built
=> the Java interface will *NOT* be built
=> the Java unit test will *NOT* be enabled
```
这个操作可能影响了 JLL 包产生的 lib
文件?