authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-02 11:59:49-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-02 12:00:16-04:00
logf8117a0799f6c691bf65f3b3f4726bf0e6fd6be2
tree349eea8711ace4e545c40f61da45ab65b6e2c704
parentf950ec0c16de6dba8a541b1a6453ebe431430782
signature Commit is signed but in an unrecognized format.

docs: update for shared libraries


1 files changed, 12 insertions(+), 12 deletions(-)

doc/langref.html.in+12-12
...@@ -8859,20 +8859,21 @@ export fn add(a: i32, b: i32) i32 {...@@ -8859,20 +8859,21 @@ export fn add(a: i32, b: i32) i32 {
8859 return a + b;8859 return a + b;
8860}8860}
8861 {#code_end#}8861 {#code_end#}
8862 <p>To make a shared library:</p>8862 <p>To make a static library:</p>
8863 <pre><code class="shell">$ zig build-lib mathtest.zig8863 <pre><code class="shell">$ zig build-lib mathtest.zig
8864</code></pre>8864</code></pre>
8865 <p>To make a static library:</p>8865 <p>To make a shared library:</p>
8866 <pre><code class="shell">$ zig build-lib mathtest.zig --static8866 <pre><code class="shell">$ zig build-lib mathtest.zig -dynamic
8867</code></pre>8867</code></pre>
8868 <p>Here is an example with the {#link|Zig Build System#}:</p>8868 <p>Here is an example with the {#link|Zig Build System#}:</p>
8869 <p class="file">test.c</p>8869 <p class="file">test.c</p>
8870 <pre><code class="cpp">// This header is generated by zig from mathtest.zig8870 <pre><code class="cpp">// This header is generated by zig from mathtest.zig
8871#include "mathtest.h"8871#include "mathtest.h"
8872#include &lt;assert.h&gt;8872#include &lt;stdio.h&gt;
88738873
8874int main(int argc, char **argv) {8874int main(int argc, char **argv) {
8875 assert(add(42, 1337) == 1379);8875 int32_t result = add(42, 1337);
8876 printf("%d\n", result);
8876 return 0;8877 return 0;
8877}</code></pre>8878}</code></pre>
8878 <p class="file">build.zig</p>8879 <p class="file">build.zig</p>
...@@ -8882,10 +8883,10 @@ const Builder = @import("std").build.Builder;...@@ -8882,10 +8883,10 @@ const Builder = @import("std").build.Builder;
8882pub fn build(b: *Builder) void {8883pub fn build(b: *Builder) void {
8883 const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0));8884 const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0));
88848885
8885 const exe = b.addCExecutable("test");8886 const exe = b.addExecutable("test", null);
8886 exe.addCompileFlags([][]const u8{"-std=c99"});8887 exe.addCSourceFile("test.c", [][]const u8{"-std=c99"});
8887 exe.addSourceFile("test.c");
8888 exe.linkLibrary(lib);8888 exe.linkLibrary(lib);
8889 exe.linkSystemLibrary("c");
88898890
8890 b.default_step.dependOn(&exe.step);8891 b.default_step.dependOn(&exe.step);
88918892
...@@ -8896,10 +8897,9 @@ pub fn build(b: *Builder) void {...@@ -8896,10 +8897,9 @@ pub fn build(b: *Builder) void {
8896}8897}
8897 {#code_end#}8898 {#code_end#}
8898 <p class="file">terminal</p>8899 <p class="file">terminal</p>
8899 <pre><code class="shell">$ zig build8900 <pre><code class="shell">$ zig build test
8900$ ./test89011379
8901$ echo $?8902</code></pre>
89020</code></pre>
8903 {#see_also|export#}8903 {#see_also|export#}
8904 {#header_close#}8904 {#header_close#}
8905 {#header_open|Mixing Object Files#}8905 {#header_open|Mixing Object Files#}