-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
增加直接将 C 库作为依赖引入的教程 #108
Comments
#107 |
这里最好加个教程,说明如何用 zon 下载 vcpkg 的依赖,怎么配置 include path 之类的 |
vcpkg是直接下载编译成lib库,按正常导入lib的方法不就可以了吗? exe.linkLibC();
exe.addIncludePath(.{ .cwd_relative = vcpkg_include_path });
exe.addLibraryPath(.{ .cwd_relative = vcpkg_library_path });
exe.linkSystemLibrary("vcpkg_lib_name"); 下载依赖什么的vcpkg自己就做好了,zig部分只用include 和 link就够了吧 |
如果 vcpkg 自己下载,zig 这边怎么获取下载的路径呢?是有什么规则嘛? |
vcpkg比如在windows-x64下把vcpkg安装在"D:\vcpkg"
vcpkg自己会下载编译,然后用指令
将库放在一起方便导入 而以上是经典的vcpkg安装库的方法,一般到这一步之后在vs直接include就够了 zig这时候要切入的点就是vcpkg将库放在一起的地方,一般是在vcpkg目录下的"installed"目录下,按照上面的例子,在安装库之后可以在"D:\vcpkg\installed\windows-x64"看到"bin"、"include"、"lib"目录。
那么之后就普通地导入c库就行了,就像我之前写的 // build.zig
exe.linkLibC();
exe.addIncludePath(.{ .cwd_relative = "D:\\vcpkg\\installed\\windows-x64\\include"});
exe.addLibraryPath(.{ .cwd_relative = "D:\\vcpkg\\installed\\windows-x64\\lib" });
exe.linkSystemLibrary("gsl"); // main.zig
const gsl = @cImport({
@cInclude("gsl/gsl_fft_complex.h");
}); |
那就是说,知道 vcpkg 的 root dir 和当前系统架构后,就可以拼出我们需要的 path 了? 如果感兴趣,可以帮我们加上这个示例。 |
注意:此处指的是无需目标C库包含
build.zig
!The text was updated successfully, but these errors were encountered: