Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f53b364

Browse files
add -Zexport-executable-symbols to unstable book
1 parent 63c748e commit f53b364

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# `export-executable-symbols`
2+
3+
The tracking issue for this feature is: [#84161](https://github.com/rust-lang/rust/issues/84161).
4+
5+
------------------------
6+
7+
The `-Zexport-executable-symbols` compiler flag makes `rustc` export symbols from executables. The resulting binary is runnable, but can also be used as a dynamic library. This is useful for interoperating with programs written in other languages, in particular languages with a runtime like Java or Lua.
8+
9+
For example on windows:
10+
```rust
11+
#[no_mangle]
12+
fn my_function() -> usize {
13+
return 42;
14+
}
15+
16+
fn main() {
17+
println!("Hello, world!");
18+
}
19+
```
20+
21+
A standard `cargo build` will produce a `.exe` without an export directory. When the `export-executable-symbols` flag is added
22+
23+
```Bash
24+
export RUSTFLAGS="-Zexport-executable-symbols"
25+
cargo build
26+
```
27+
28+
the binary has an export directory with the functions:
29+
30+
```plain
31+
The Export Tables (interpreted .edata section contents)
32+
33+
...
34+
35+
[Ordinal/Name Pointer] Table
36+
[ 0] my_function
37+
[ 1] main
38+
```
39+
(the output of `objdump -x` on the binary)
40+
41+
Please note that the `#[no_mangle]` attribute is required. Without it, the symbol is not exported.
42+
43+
The equivalent of this flag in C and C++ compilers is the `__declspec(dllexport)` annotation or the `-rdynamic` linker flag.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /