From c419ece7cde4e395c813545243fc54b9936457db Mon Sep 17 00:00:00 2001 From: Manlio Perillo Date: Thu, 19 Jan 2023 16:11:06 +0100 Subject: [PATCH] doctest: make the "Exporting a C Library" example work The mathtest example of exporting a library with the C ABI it not working, since the mathtest.h file is not generated. Update the shell sample, adding the -femit-h flag to the zig build-lib command. Show an example of how to copy the zig.h file to the project directory, using zig env and jq. I'm not sure if there is a better/official method. --- doc/langref.html.in | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/langref.html.in b/doc/langref.html.in index 30dbbb604e5d..493703548612 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -10901,9 +10901,15 @@ export fn add(a: i32, b: i32) i32 { } {#code_end#}

To make a static library:

- {#shell_samp#}$ zig build-lib mathtest.zig{#end_shell_samp#} + {#shell_samp#}$ zig build-lib -femit-h mathtest.zig{#end_shell_samp#}

To make a shared library:

- {#shell_samp#}$ zig build-lib mathtest.zig -dynamic{#end_shell_samp#} + {#shell_samp#}$ zig build-lib -femit-h mathtest.zig -dynamic{#end_shell_samp#} +

+ The -femit-h flag is necessary in order to generate the mathtest.h file. + The generated C header file includes the zig.h file that must be copied + to the project directory, as an example using jq: +

+ {#shell_samp#}cp $(zig env | jq -r .lib_dir)/zig.h .{#end_shell_samp#}

Here is an example with the {#link|Zig Build System#}:

{#syntax_block|c|test.c#}// This header is generated by zig from mathtest.zig #include "mathtest.h"