| ... | @@ -6215,6 +6215,35 @@ test "main" { | ... | @@ -6215,6 +6215,35 @@ test "main" { |
| 6215 | <p> | 6215 | <p> |
| 6216 | Creates a symbol in the output object file. | 6216 | Creates a symbol in the output object file. |
| 6217 | </p> | 6217 | </p> |
| | 6218 | <p> |
| | 6219 | This function can be called from a {#link|comptime#} block to conditionally export symbols. |
| | 6220 | When {#syntax#}target{#endsyntax#} is a function with the C calling convention and |
| | 6221 | {#syntax#}linkage{#endsyntax#} is {#syntax#}Strong{#endsyntax#}, this is equivalent to |
| | 6222 | the {#syntax#}export{#endsyntax#} keyword used on a function: |
| | 6223 | </p> |
| | 6224 | {#code_begin|obj#} |
| | 6225 | const builtin = @import("builtin"); |
| | 6226 | |
| | 6227 | comptime { |
| | 6228 | @export("foo", internalName, builtin.GlobalLinkage.Strong); |
| | 6229 | } |
| | 6230 | |
| | 6231 | extern fn internalName() void {} |
| | 6232 | {#code_end#} |
| | 6233 | <p>This is equivalent to:</p> |
| | 6234 | {#code_begin|obj#} |
| | 6235 | export fn foo() void {} |
| | 6236 | {#code_end#} |
| | 6237 | <p>Note that even when using {#syntax#}export{#endsyntax#}, {#syntax#}@"foo"{#endsyntax#} syntax can |
| | 6238 | be used to choose any string for the symbol name:</p> |
| | 6239 | {#code_begin|obj#} |
| | 6240 | export fn @"A function name that is a complete sentence."() void {} |
| | 6241 | {#code_end#} |
| | 6242 | <p> |
| | 6243 | When looking at the resulting object, you can see the symbol is used verbatim: |
| | 6244 | </p> |
| | 6245 | <pre>00000000000001f0 T A function name that is a complete sentence.</pre> |
| | 6246 | {#see_also|Exporting a C Library#} |
| 6218 | {#header_close#} | 6247 | {#header_close#} |
| 6219 | | 6248 | |
| 6220 | {#header_open|@fence#} | 6249 | {#header_open|@fence#} |
| ... | @@ -8074,6 +8103,7 @@ pub fn build(b: *Builder) void { | ... | @@ -8074,6 +8103,7 @@ pub fn build(b: *Builder) void { |
| 8074 | $ ./test | 8103 | $ ./test |
| 8075 | $ echo $? | 8104 | $ echo $? |
| 8076 | 0</code></pre> | 8105 | 0</code></pre> |
| | 8106 | {#see_also|export#} |
| 8077 | {#header_close#} | 8107 | {#header_close#} |
| 8078 | {#header_open|Mixing Object Files#} | 8108 | {#header_open|Mixing Object Files#} |
| 8079 | <p> | 8109 | <p> |