File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,32 @@ libc = "0.2.0"
21
21
22
22
[ libc ] : https://crates.io/crates/libc
23
23
24
+ ## Prepare the build script
25
+
26
+ Because [ snappy] ( https://github.com/google/snappy ) is a static library by default.
27
+ So there is no C++ std linked in the output artifact.
28
+ n order to use this foreign library in Rust, we have to manually specify that we want to link stdc++ in our project.
29
+ The easiest way to do this is by setting up a build script.
30
+
31
+ First edit ` Cargo.toml ` , inside ` package ` add ` build = "build.rs" ` :
32
+ ``` toml
33
+ [package ]
34
+ ...
35
+ build = " build.rs"
36
+ ```
37
+
38
+ Then create a new file at the root of your workspace, named ` build.rs ` :
39
+ ``` rust
40
+ // build.rs
41
+ fn main () {
42
+ println! (" cargo:rustc-link-lib=dylib=stdc++" ); // This line may be unnecessary for some environment.
43
+ println! (" cargo:rustc-link-search=<YOUR SNAPPY LIBRARY PATH>" );
44
+ }
45
+ ```
46
+
47
+ For more information, please read [ The Cargo Book - build script] ( https://doc.rust-lang.org/cargo/reference/build-scripts.html ) .
48
+
49
+
24
50
## Calling foreign functions
25
51
26
52
The following is a minimal example of calling a foreign function which will
You can’t perform that action at this time.
0 commit comments