{"id":10008036,"date":"2023-07-05T14:59:24","date_gmt":"2023-07-05T06:59:24","guid":{"rendered":"https:\/\/ityet.com\/?p=10008036"},"modified":"2023-07-05T14:59:24","modified_gmt":"2023-07-05T06:59:24","slug":"%e6%96%87%e7%9b%98rust-ffi-%e6%b5%85%e5%b0%9d-%e4%ba%ac%e4%b8%9c%e4%ba%91%e6%8a%80%e6%9c%af%e5%9b%a2%e9%98%9f","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10008036","title":{"rendered":"\u6587\u76d8Rust &#8212;  FFI \u6d45\u5c1d | \u4eac\u4e1c\u4e91\u6280\u672f\u56e2\u961f"},"content":{"rendered":"<p>rust FFI \u662frust\u4e0e\u5176\u4ed6\u8bed\u8a00\u4e92\u8c03\u7684\u6865\u6881\uff0c\u901a\u8fc7FFI rust \u53ef\u4ee5\u6709\u6548\u7ee7\u627f C \u8bed\u8a00\u7684\u5386\u53f2\u8d44\u4ea7\u3002\u672c\u671f\u901a\u8fc7\u51e0\u4e2a\u4f8b\u5b50\u6765\u804a\u804arust\u4e0eC \u8bed\u8a00\u4ea4\u4e92\u7684\u5177\u4f53\u6b65\u9aa4\u3002<\/p>\n<h2>\u573a\u666f\u4e00 \u8c03\u7528C\u4ee3\u7801<\/h2>\n<p>\u521b\u5efa\u5de5\u7a0b<\/p>\n<pre><code class=\"shell\">cargo new --bin ffi_sample\n\n\n\n<\/code><\/pre>\n<p>Cargo.toml \u914d\u7f6e<\/p>\n<pre><code class=\"toml\">[package]\nname = &quot;ffi_sample&quot;\nversion = &quot;0.1.0&quot;\nedition = &quot;2021&quot;\nbuild = &quot;build.rs&quot;\n\n# See more keys and their definitions at https:\/\/doc.rust-lang.org\/cargo\/reference\/manifest.html\n\n[build-dependencies]\ncc = &quot;1.0.79&quot;\n\n[dependencies]\nlibc = &quot;0.2.146&quot;\nlibloading = &quot;0.8.0&quot;\n\n\n\n<\/code><\/pre>\n<p>\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684c\u7a0b\u5e8fsample.c<\/p>\n<pre><code class=\"C\">int add(int a,int b){\n    return a+b;\n}\n\n\n\n<\/code><\/pre>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=dC8pUzjK3iCoUWXm7OHqbA%3D%3D.HAgRpGA0r2KD93PMCT6OZA%3D%3D\" rel=\"nofollow\">main.rs<\/a><\/p>\n<pre><code class=\"rust\">use std::os::raw::c_int;\n\n\n#[link(name = &quot;sample&quot;)]\nextern &quot;C&quot; {\n    fn add(a: c_int, b: c_int) -&gt; c_int;\n}\n\nfn main() {\n    let r = unsafe { add(2, 18) };\n    println!(&quot;{:?}&quot;, r);\n}\n\n\n\n<\/code><\/pre>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=PCP%2F8adBbDAM9oi1V29AIA%3D%3D.f5b84rKOTp6sut7DLS2DMQ%3D%3D\" rel=\"nofollow\">build.rs<\/a><\/p>\n<pre><code class=\"rust\">\nfn main() {\n    cc::Build::new().file(&quot;sample.c&quot;).compile(&quot;sample&quot;);\n}\n\n\n\n\n<\/code><\/pre>\n<p>\u4ee3\u7801\u76ee\u5f55\u6811<\/p>\n<pre><code class=\"shell\">.\n\u251c\u2500\u2500 Cargo.lock\n\u251c\u2500\u2500 Cargo.toml\n\u251c\u2500\u2500 build.rs\n\u251c\u2500\u2500 sample.c\n\u2514\u2500\u2500 src\n \u00a0\u00a0 \u2514\u2500\u2500 main.rs\n\n\n\n<\/code><\/pre>\n<pre><code class=\"shell\">cargo run\n\n\n\n<\/code><\/pre>\n<h2>\u573a\u666f\u4e8c \u4f7f\u7528bindgen \u901a\u8fc7\u5934\u6587\u4ef6\u7ed1\u5b9ac\u8bed\u8a00\u52a8\u6001\u94fe\u63a5\u5e93<\/h2>\n<p>\u4fee\u6539Cargo.toml,\u65b0\u589ebindgen\u4f9d\u8d56<\/p>\n<pre><code class=\"toml\">[package]\nname = &quot;ffi_sample&quot;\nversion = &quot;0.1.0&quot;\nedition = &quot;2021&quot;\nbuild = &quot;build.rs&quot;\n\n# See more keys and their definitions at https:\/\/doc.rust-lang.org\/cargo\/reference\/manifest.html\n\n[build-dependencies]\ncc = &quot;1.0.79&quot;\nbindgen = &quot;0.65.1&quot;\n\n[dependencies]\nlibc = &quot;0.2.146&quot;\nlibloading = &quot;0.8.0&quot;\n\n\n\n<\/code><\/pre>\n<p>\u65b0\u589e sample.h \u5934\u6587\u4ef6<\/p>\n<pre><code class=\"C\">#ifndef ADD_H\n#define ADD_H\n\nint add(int a, int b);\n\n#endif\n\n\n\n<\/code><\/pre>\n<p>\u65b0\u589e wrapper.h \u5934\u6587\u4ef6 wrapper.h \u6587\u4ef6\u5c06\u5305\u62ec\u6240\u6709\u5404\u79cd\u5934\u6587\u4ef6\uff0c\u8fd9\u4e9b\u5934\u6587\u4ef6\u5305\u542b\u6211\u4eec\u60f3\u8981\u7ed1\u5b9a\u7684\u7ed3\u6784\u548c\u51fd\u6570\u7684\u58f0\u660e<\/p>\n<pre><code class=\"C\">#include &quot;sample.h&quot;;\n\n\n\n<\/code><\/pre>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=EVW%2BVGp7kAlOyQFmBvRO0g%3D%3D.jVQS%2B%2BN7BCcAeQZuBY0On8IWMed7SwG7tCZ9strI71E%3D\" rel=\"nofollow\">\u6539\u5199build.rs<\/a> \u7f16\u8bd1 sample.c <a href=\"https:\/\/link.segmentfault.com\/?enc=VphyGhkj3%2Ffe47zN3f%2BgwQ%3D%3D.rAaCBXIqFkZu52qTDD8YCFtK7TyFOTtlKblywgyrcFdMVmPwwlSVpn0mir%2BOEM52\" rel=\"nofollow\">\u751f\u6210\u52a8\u6001\u94fe\u63a5\u5e93sample.so<\/a>;\u901a\u8fc7bindgen\u751f\u6210rust binding c \u7684\u4ee3\u7801\u5e76\u8f93\u51fa\u5230 bindings \u76ee\u5f55<\/p>\n<pre><code class=\"rust\">use std::path::PathBuf;\n\nfn main() {\n    \/\/ \u53c2\u8003cc \u6587\u6863\n    println!(&quot;cargo:rerun-if-changed=sample.c&quot;);\n    cc::Build::new()\n        .file(&quot;sample.c&quot;)\n        .shared_flag(true)\n        .compile(&quot;sample.so&quot;);\n    \/\/ \u53c2\u8003 https:\/\/doc.rust-lang.org\/cargo\/reference\/build-scripts.html\n    println!(&quot;cargo:rustc-link-lib=sample.so&quot;);\n    println!(&quot;cargo:rerun-if-changed=sample.h&quot;);\n    let bindings = bindgen::Builder::default()\n        .header(&quot;wrapper.h&quot;)\n        .parse_callbacks(Box::new(bindgen::CargoCallbacks))\n        .generate()\n        .expect(&quot;Unable to generate bindings&quot;);\n\n    let out_path = PathBuf::from(&quot;bindings&quot;);\n    bindings\n        .write_to_file(out_path.join(&quot;sample_bindings.rs&quot;))\n        .expect(&quot;Couldn't write bindings!&quot;);\n}\n\n\n\n<\/code><\/pre>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=HHe9ZJZiMB4Xig0TKiZA5g%3D%3D.bUDYhLYscze%2BYZczL46ZQu7c2flPuF%2Bo10PsYWKmYlY%3D\" rel=\"nofollow\">\u4fee\u6539main.rs<\/a> include \u5b8f\u5f15\u5165sample \u52a8\u6001\u94fe\u63a5\u5e93\u7684binding\u3002\u4ee5\u524d\u6211\u4eec\u81ea\u5df1\u624b\u5199\u7684C\u51fd\u6570\u7ed1\u5b9a\u5c31\u4e0d\u9700\u8981\u4e86\uff0c\u770b\u770bbindings\/sample_bindings.rs \u7684\u5185\u5bb9\u4e0e\u6211\u4eec\u624b\u5199\u7684\u51fd\u6570\u7ed1\u5b9a\u662f\u7b49\u6548\u7684<\/p>\n<pre><code class=\"Rust\">include!(&quot;..\/bindings\/sample_bindings.rs&quot;);\n\n\/\/ #[link(name = &quot;sample&quot;)]\n\/\/ extern &quot;C&quot; {\n\/\/     fn add(a: c_int, b: c_int) -&gt; c_int;\n\/\/ }\n\nfn main() {\n    let r = unsafe { add(2, 18) };\n    println!(&quot;{:?}&quot;, r);\n}\n\n\n\n\n<\/code><\/pre>\n<p>\u4ee3\u7801\u76ee\u5f55\u6811<\/p>\n<pre><code class=\"shell\">.\n\u251c\u2500\u2500 Cargo.lock\n\u251c\u2500\u2500 Cargo.toml\n\u251c\u2500\u2500 bindings\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 sample_bindings.rs\n\u251c\u2500\u2500 build.rs\n\u251c\u2500\u2500 sample.c\n\u251c\u2500\u2500 sample.h\n\u251c\u2500\u2500 src\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 main.rs\n\u2514\u2500\u2500 wrapper.h\n\n\n\n<\/code><\/pre>\n<p>ffi_sample \u5de5\u7a0b\u7684\u5b8c\u6574\u4ee3\u7801<a href=\"https:\/\/link.segmentfault.com\/?enc=msYKWg3GWkrDE5gL80RfDQ%3D%3D.ssr538Yc9Hb%2FGUp%2FSkBMA3%2BLtvaZDrkMXwXpu809CVi9uKErQnKDGT%2F7eJkpIxfMx9UECHbhWHew2cA6m5OUXw%3D%3D\" rel=\"nofollow\">\u4f4d\u7f6e<\/a>,\u8bfb\u8005\u53ef\u4ee5clone <a href=\"https:\/\/link.segmentfault.com\/?enc=BkoaZg20iWiatt8XsqprLg%3D%3D.3ChgNoRB9IRr8p0ZdSjdUXkutDEIxXIyorhqg%2FbxpZK%2BT2a8NuGmcCsbi7erdesn09C%2FWWP4Nr%2Fb8rAnwU%2FRdPUJhc%2FMa6uxaKspKBXCfJ5Y1%2FJiGDY7cTa0W5fZPEJ0\" rel=\"nofollow\">https:\/\/github.com\/jiashiwen\/wenpanrust\uff0c\u76f4\u63a5\u8fd0\u884c\u5373\u53ef<\/a><\/p>\n<pre><code class=\"shell\">cargo run -p ffi_sample\n\n\n\n<\/code><\/pre>\n<h2>\u573a\u666f\u4e09 \u5c01\u88c5\u4e00\u4e2ac\u7f16\u5199\u7684\u5e93<\/h2>\n<p>secp256k1\u662f\u4e00\u4e2a\u692d\u5706\u66f2\u7ebf\u8ba1\u7b97\u7684 clib\uff0c\u8fd9\u73a9\u610f\u513f\u5728\u5bc6\u7801\u5b66\u548c\u9690\u79c1\u8ba1\u7b97\u65b9\u9762\u7684\u5e38\u7528\u7b97\u6cd5\uff0c\u4e0b\u9762\u6211\u4eec\u4ece\u5de5\u7a0b\u65b9\u9762\u770b\u770b\u5c01\u88c5secp256k1\u5982\u4f55\u64cd\u4f5c<\/p>\n<pre><code class=\"shell\">cargo new --lib wrapper_secp256k1\n\n\n\n<\/code><\/pre>\n<p>cargo.toml<\/p>\n<pre><code class=\"toml\">[package]\nname = &quot;wrapper_secp256k1&quot;\nversion = &quot;0.1.0&quot;\nedition = &quot;2021&quot;\n\n# See more keys and their definitions at https:\/\/doc.rust-lang.org\/cargo\/reference\/manifest.html\n[build-dependencies]\ncc = &quot;1.0.79&quot;\nbindgen = &quot;0.65.1&quot;\n\n[dependencies]\n\n\n\n<\/code><\/pre>\n<p>git \u5f15\u5165 submodule<\/p>\n<pre><code class=\"shell\">cd wrapper_secp256k1\ngit submodule add https:\/\/github.com\/bitcoin-core\/secp256k1  wrapper_secp256k1\/secp256k1_sys \n\n\n\n<\/code><\/pre>\n<p>\u5de5\u7a0b\u4e0b\u65b0\u5efabindings\u76ee\u5f55\u7528\u6765\u5b58\u653e\u7ed1\u5b9a\u6587\u4ef6\uff0c\u8be5\u76ee\u5f55\u4e0esrc\u5e73\u7ea7<\/p>\n<p>wrapper.h<\/p>\n<pre><code class=\"c\">#include &quot;secp256k1_sys\/secp256k1\/include\/secp256k1.h&quot;\n\n\n\n<\/code><\/pre>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=Vyn9OBLVE%2Bg02oDDdPIsNw%3D%3D.NJ7JjwPC9vz12rxkX87x%2Fw%3D%3D\" rel=\"nofollow\">build.rs<\/a><\/p>\n<pre><code class=\"rust\">use std::path::PathBuf;\n\nfn main() {\n    println!(&quot;cargo:rustc-link-lib=secp256k1&quot;);\n    println!(&quot;cargo:rerun-if-changed=wrapper.h&quot;);\n    let bindings = bindgen::Builder::default()\n        .header(&quot;wrapper.h&quot;)\n        .parse_callbacks(Box::new(bindgen::CargoCallbacks))\n        .generate()\n        .expect(&quot;Unable to generate bindings&quot;);\n\n    let out_path = PathBuf::from(&quot;bindings&quot;);\n    bindings\n        .write_to_file(out_path.join(&quot;bindings.rs&quot;))\n        .expect(&quot;Couldn't write bindings!&quot;);\n}\n\n\n\n<\/code><\/pre>\n<p>cargo build \u901a\u8fc7<\/p>\n<p>\u7f16\u5199\u6d4b\u8bd5 <a href=\"https:\/\/link.segmentfault.com\/?enc=oFTtJBYltSlqXH%2F6MgPHYA%3D%3D.hlbEDgvm9RXCqQu4cH45xg%3D%3D\" rel=\"nofollow\">lib.rs<\/a><\/p>\n<pre><code class=\"rust\">include!(&quot;..\/bindings\/secp256k1.rs&quot;);\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    #[test]\n    fn test_create_pubkey() {\n        \/\/ secp256k1\u8fd4\u56de\u516c\u94a5\n        let mut pubkey: secp256k1_pubkey = secp256k1_pubkey { data: [0; 64] };\n        let prikey: u8 = 1;\n\n        unsafe {\n            let context = secp256k1_context_create(SECP256K1_CONTEXT_SIGN);\n            assert!(!context.is_null());\n            let ret = secp256k1_ec_pubkey_create(&amp;*context, &amp;mut pubkey, &amp;prikey);\n            assert_eq!(ret, 1);\n        }\n    }\n}\n\n\n\n<\/code><\/pre>\n<p>\u8fd0\u884c\u6d4b\u8bd5 cargo test \u62a5\u9519<\/p>\n<pre><code class=\"shell\">warning: `wrapper_secp256k1` (lib) generated 5 warnings\nerror: linking with `cc` failed: exit status: 1\n  |\n  = note: LC_ALL=&quot;C&quot; PATH=&quot;\/usr\/local\/Cellar\/rust\/1.70.0\/lib\/rustlib\/x86_64-apple-darwin\/bin:\/Users\/jiashiwen\/local\/Cellar\/rust\/1.70.0\/lib\/rustlib\/x86_64-apple-darwin\/lib\/libobject-6d1da0e5d7930106.rlib&quot; &quot;\/usr\/local\/Cellar\/rust\/1.70.0\/lib\/rustlib\/x86_64-apple-darwin\/lib\/libmemchr-d6d74858e37ed726.rlib&quot; &quot;\/usr\/local\/Cellar\/rust\/1.70.0\/lib\/rustlib\/x86_64-apple-darwin\/lib\/libaddr2line-d75e66c6c1b76fdd.rlib&quot; &quot;\/usr\/local\/Cellar\/rust\/1.70.0\/lib\/rustlib\/x86_64-apple-darwin\/lib\/libgimli-546ea342344e3761.rlib&quot; &quot;\/usr\/local\/Cellar\/rust\/1.70.0\/lib\/rustlib\/x86_64-apple-darwin\/lib\/librustc_demangle-8ad10e36ca13f067.rlib&quot; &quot;\/usr\/local\/Cellar\/rust\/1.70.0\/lib\/rustlib\/x86_64-apple-darwin\/lib\/libstd_detect-0543b8486ac00cf6.rlib&quot; &quot;\/usr\/local\/Cellar\/rust\/1.70.0\/lib\/rustlib\/x86_64-apple-darwin\/lib\/libhashbrown-7f0d42017ce08763.rlib&quot; &quot;\/usr\/local\/Cellar\/rust\/1.70.0\/lib\/rustlib\/x86_64-apple-darwin\/lib\/libminiz_oxide-65e6b9c4725e3b7f.rlib&quot; &quot;\/usr\/local\/Cellar\/rust\/1.70.0\/lib\/rustlib\/x86_64-apple-darwin\/lib\/libadler-131157f72607aea7.rlib&quot; &quot;\/usr\/local\/Cellar\/rust\/1.70.0\/lib\/rustlib\/x86_64-apple-darwin\/lib\/librustc_std_workspace_alloc-f7d15060b16c135d.rlib&quot; &quot;\/usr\/local\/Cellar\/rust\/1.70.0\/lib\/rustlib\/x86_64-apple-darwin\/lib\/libunwind-a52bfac5ae872be2.rlib&quot; &quot;\/usr\/local\/Cellar\/rust\/1.70.0\/lib\/rustlib\/x86_64-apple-darwin\/lib\/libcfg_if-1762d9ac100ea3e7.rlib&quot; &quot;\/usr\/local\/Cellar\/rust\/1.70.0\/lib\/rustlib\/x86_64-apple-darwin\/lib\/liblibc-f8e0e4708f61f3f4.rlib&quot; &quot;\/usr\/local\/Cellar\/rust\/1.70.0\/lib\/rustlib\/x86_64-apple-darwin\/lib\/liballoc-af9a608dd9cb26b2.rlib&quot; &quot;\/usr\/local\/Cellar\/rust\/1.70.0\/lib\/rustlib\/x86_64-apple-darwin\/lib\/librustc_std_workspace_core-9777023438fd3d6a.rlib&quot; &quot;\/usr\/local\/Cellar\/rust\/1.70.0\/lib\/rustlib\/x86_64-apple-darwin\/lib\/libcore-83ca6d61eb70e9b8.rlib&quot; &quot;\/usr\/local\/Cellar\/rust\/1.70.0\/lib\/rustlib\/x86_64-apple-darwin\/lib\/libcompiler_builtins-ea2ca6e1df0449b8.rlib&quot; &quot;-lSystem&quot; &quot;-lc&quot; &quot;-lm&quot; &quot;-L&quot; &quot;\/usr\/local\/Cellar\/rust\/1.70.0\/lib\/rustlib\/x86_64-apple-darwin\/lib&quot; &quot;-o&quot; &quot;\/Users\/jiashiwen\/rustproject\/wrapper_secp256k1\/target\/debug\/deps\/wrapper_secp256k1-4bf30c62ecfdf2a7&quot; &quot;-Wl,-dead_strip&quot; &quot;-nodefaultlibs&quot;\n  = note: ld: library not found for -lsecp256k1\n          clang: error: linker command failed with exit code 1 (use -v to see invocation)\n\n\nwarning: `wrapper_secp256k1` (lib test) generated 5 warnings (5 duplicates)\nerror: could not compile `wrapper_secp256k1` (lib test) due to previous error; 5 warnings emitted\n\n\n\n<\/code><\/pre>\n<p>\u62a5\u9519\u663e\u793a\u627e\u4e0d\u5230\u7f16\u8bd1 secp256k1 \u76f8\u5bf9\u5e94\u7684\u5e93\u3002<\/p>\n<p>\u624b\u52a8\u7f16\u8bd1secp256k1<\/p>\n<pre><code class=\"shell\">cd secp256k1_sys\n.\/autogen.sh\n.\/configure\nmake\nmake install\n\n\n\n<\/code><\/pre>\n<p>\u7f16\u8bd1\u5b8c\u6210\u540e\uff0c\u6d4b\u8bd5\u901a\u8fc7<\/p>\n<p>\u5176\u5b9e secp256k1 \u6709\u5bf9\u5e94\u7684 <a href=\"https:\/\/link.segmentfault.com\/?enc=U7ewqr7lAZf4%2BZB%2F5YG5dA%3D%3D.kjr4iD30idtv4KVKD8uiu2fJTvSf7%2Btu0GpIGWbg3aT4FNJgaV0nWXbVrWcAYuvA\" rel=\"nofollow\">rust wrapper<\/a>,\u6211\u4eec\u8fd9\u91cc\u53ea\u662f\u5c55\u793a\u4e00\u4e0b\u5c01\u88c5\u7684\u8fc7\u7a0b\u3002<\/p>\n<p>wrapper_secp256k1 \u5de5\u7a0b\u7684\u5b8c\u6574\u4ee3\u7801<a href=\"https:\/\/link.segmentfault.com\/?enc=7w9mbhCijBp9SYtbcJ10mQ%3D%3D.MksAvCcEiuJFjDyf7DaPZ%2FekKUsYc2FU4afJqslCN1KjSFiRwvPYIrvuNysylluWh9qfJ4Ow%2FLHR1XpE99lmFQWrDyWevrQ96Z4MQgMyH08%3D\" rel=\"nofollow\">\u4f4d\u7f6e<\/a>,\u6709\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5clone <a href=\"https:\/\/link.segmentfault.com\/?enc=ZjbnIgSxJZOGRbkb0oi8Tw%3D%3D.7Fr3cAbia%2Bi5ovATIMcyzI88kdmfmCpoT00%2FD3vefiBfZhpaZtxoII9cI7qhKqfViG2QWifEc9gvLCIg3SCdpFhb9ZkvOfbYIOOTikIBErgmkUrNW2PeTfUyyv5n1raURMzH7bOR1mXFJwi2kAXfAa%2FkJ1ndi3Yp1a9xHpZbsBqpaDEOX30X2BGHTfGAIWngqfV2EDWeUqgAwJRXx7uZXjYoRW%2BFAgsTZ0eRWQ2VXmg%3D\" rel=\"nofollow\">https:\/\/github.com\/jiashiwen\/wenpanrust\u3002<\/a>\u901a\u8fc7\u4ee5\u4e0b\u64cd\u4f5c\u67e5\u770b\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<ul>\n<li>\n<p>clone \u9879\u76ee<\/p>\n<pre><code class=\"shell\">git clone https:\/\/github.com\/jiashiwen\/wenpanrust\ncd wenpanrust\n\n\n\n<\/code><\/pre>\n<\/li>\n<li>\n<p>update submodule<\/p>\n<pre><code class=\"shell\">git submodule init\ngit submodule update\n\n\n\n<\/code><\/pre>\n<\/li>\n<li>\n<p>\u7f16\u8bd1 secp256k1<\/p>\n<pre><code class=\"shell\">cd wrapper_secp256k1\/secp256k1_sys \n.\/autogen.sh\n.\/configure\nmake\nmake install  \n\n\n\n<\/code><\/pre>\n<\/li>\n<li>\n<p>run test<\/p>\n<pre><code class=\"shell\">cargo test -p wrapper_secp256k1\n\n\n\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<p>\u53c2\u8003\u8d44\u6599<\/p>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=go5ECqdPBWVtq2iYHDxhiA%3D%3D.pLvrLj95KEW94sR9ZWuuFR4jyRdC21Tw6WdkJAHI16b1OsINqX4wrx6hJFwkmc0jwb6wRgL8UsIjuZj1ksFfVu8Z1umKCRixYwkJ%2B6PAncJlY%2FTNdGuZ7C1wOt%2BfqnfB\" rel=\"nofollow\">Rust FFI (C vs Rust)\u5b66\u4e60\u6742\u8bb0.pdf<\/a>%E5%AD%A6%E4%B9%A0%E6%9D%82%E8%AE%B0.pdf)  <br \/><a href=\"https:\/\/link.segmentfault.com\/?enc=3pP2wCAmHvWnxeoxRNU5jg%3D%3D.2aER1VupouRiGI9Y2hnWd6l34md7Aws9E%2BuWWf6n7hf9PO40ILYr5Dspv6oFIQBSFosJSl6T3hVMmMbFXbEWLg%3D%3D\" rel=\"nofollow\">bindgen\u5b98\u65b9\u6587\u6863<\/a>  <br \/><a href=\"https:\/\/link.segmentfault.com\/?enc=1NzU%2BXpYOw79hXrdABTPjw%3D%3D.qHkBwhEtzArK8BHMTJbVEJi76mP4V9xNwEsF6hejeazNrYF1QZgvY79dLJ9FR81veIP1lQaGEO4tUrFAfwckpKKFy7UjLO4af6RteRpSAyU%3D\" rel=\"nofollow\">Rust FFI \u7f16\u7a0b &#8211; bindgen \u4f7f\u7528\u793a\u4f8b<\/a><\/p>\n<blockquote>\n<p>\u4f5c\u8005\uff1a\u4eac\u4e1c\u79d1\u6280 \u8d3e\u4e16\u95fb<\/p>\n<p>\u6765\u6e90\uff1a\u4eac\u4e1c\u4e91\u5f00\u53d1\u8005\u793e\u533a<\/p>\n<\/blockquote>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000043972261\">https:\/\/segmentfault.com\/a\/1190000043972261<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>rust FFI \u662frust\u4e0e\u5176\u4ed6\u8bed\u8a00\u4e92\u8c03\u7684\u6865\u6881\uff0c\u901a\u8fc7FFI rust \u53ef\u4ee5\u6709\u6548\u7ee7\u627f C \u8bed\u8a00\u7684\u5386\u53f2\u8d44\u4ea7\u3002\u672c\u671f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10008036","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008036","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10008036"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008036\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10008036"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10008036"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10008036"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}