我目前正在开发一个使用 C 和 Rust 的应用程序,当以以下任何一种方式使用它时,我没有任何问题:
C ->- 锈 -> C (雨燕( C -> Rust
- -> 示例(控制台 Rust(
但是当我想通过红豆杉中的wasm访问时,它变得越来越复杂
C ->- 锈蚀 -> 红豆杉/WASM(货物卷材启动(
链接器引发错误:"math.h"缺失
维基百科引用: https://en.wikipedia.org/wiki/C_mathematical_functions
在 Linux 和 BSD 下,数学函数(如 中所述(被单独捆绑在数学库 libm 中。因此,如果使用其中任何一个函数,则必须为链接器提供指令 -lm。
虽然我添加了标志,但它并没有改变任何东西......
下面我包含了我的库文件绑定 C -> Rust 中的build.rs
文件:
use std::env;
use std::path::Path;
fn main() {
let dir = env::var("CARGO_MANIFEST_DIR").unwrap();
cc::Build::new()
.flag("-g")
// .flag("-09")
.flag("-lm") // math.h for wasm (dosen't work or without)
.flag("-Wall")
.file(Path::new(&dir).join("src/swisseph/2.08/src/swecl.c"))
.file(Path::new(&dir).join("src/swisseph/2.08/src/swedate.c"))
.file(Path::new(&dir).join("src/swisseph/2.08/src/swehel.c"))
.file(Path::new(&dir).join("src/swisseph/2.08/src/swehouse.c"))
.file(Path::new(&dir).join("src/swisseph/2.08/src/swejpl.c"))
.file(Path::new(&dir).join("src/swisseph/2.08/src/swemmoon.c"))
.file(Path::new(&dir).join("src/swisseph/2.08/src/swemplan.c"))
.file(Path::new(&dir).join("src/swisseph/2.08/src/swepcalc.c"))
.file(Path::new(&dir).join("src/swisseph/2.08/src/sweph.c"))
.file(Path::new(&dir).join("src/swisseph/2.08/src/swephlib.c"))
.compile("swe")
}
这是我在红豆杉中编译的错误日志(货物网络启动(
Compiling libswe-sys v0.1.4
Compiling stdweb v0.4.20
error: failed to run custom build command for libswe-sys v0.1.4
--- stdout
TARGET = Some("wasm32-unknown-unknown")
OPT_LEVEL = Some("0")
HOST = Some("x86_64-apple-darwin")
CC_wasm32-unknown-unknown = None
CC_wasm32_unknown_unknown = None
TARGET_CC = None
CC = None
CFLAGS_wasm32-unknown-unknown = None
CFLAGS_wasm32_unknown_unknown = None
TARGET_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("true")
running: "clang" "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-Wall" "-Wextra" "-g" "-lm" "-Wall" "-o" "/Users/stephanebressani/Code/Rust/yewastrology/target/wasm32-unknown-unknown/debug/build/libswe-sys-2679bddccf8cd805/out/swedate.o" "-c" "/Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.4/src/swisseph/2.08/src/swedate.c"
running: "clang" "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-Wall" "-Wextra" "-g" "-lm" "-Wall" "-o" "/Users/stephanebressani/Code/Rust/yewastrology/target/wasm32-unknown-unknown/debug/build/libswe-sys-2679bddccf8cd805/out/swecl.o" "-c" "/Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.4/src/swisseph/2.08/src/swecl.c"
running: "clang" "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-Wall" "-Wextra" "-g" "-lm" "-Wall" "-o" "/Users/stephanebressani/Code/Rust/yewastrology/target/wasm32-unknown-unknown/debug/build/libswe-sys-2679bddccf8cd805/out/swehel.o" "-c" "/Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.4/src/swisseph/2.08/src/swehel.c"
cargo:warning=clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
cargo:warning=clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
cargo:warning=clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.4/src/swisseph/2.08/src/swedate.c:86:
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.4/src/swisseph/2.08/src/swephexp.h:83:
cargo:warning=/Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.4/src/swisseph/2.08/src/sweodef.h:167:10: fatal error: 'math.h' file not found
cargo:warning=#include <math.h>
cargo:warning= ^~~~~~~~
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.4/src/swisseph/2.08/src/swecl.c:62:
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.4/src/swisseph/2.08/src/swejpl.h:67:
cargo:warning=/Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.4/src/swisseph/2.08/src/sweodef.h:167:10: fatal error: 'math.h' file not found
cargo:warning=#include <math.h>
cargo:warning= ^~~~~~~~
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.4/src/swisseph/2.08/src/swehel.c:68:
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.4/src/swisseph/2.08/src/swephexp.h:83:
cargo:warning=/Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.4/src/swisseph/2.08/src/sweodef.h:167:10: fatal error: 'math.h' file not found
cargo:warning=#include <math.h>
cargo:warning= ^~~~~~~~`
cargo:warning=1 error generated.
exit code: 1
running: "clang" "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-Wall" "-Wextra" "-g" "-lm" "-Wall" "-o" "/Users/stephanebressani/Code/Rust/yewastrology/target/wasm32-unknown-unknown/debug/build/libswe-sys-2679bddccf8cd805/out/swehouse.o" "-c" "/Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.4/src/swisseph/2.08/src/swehouse.c"
cargo:warning=1 error generated.
exit code: 1
cargo:warning=clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
cargo:warning=1 error generated.
exit code: 1
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.4/src/swisseph/2.08/src/swehouse.c:63:
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.4/src/swisseph/2.08/src/swephexp.h:83:
cargo:warning=/Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.4/src/swisseph/2.08/src/sweodef.h:167:10: fatal error: 'math.h' file not found
cargo:warning=#include <math.h>
cargo:warning= ^~~~~~~~
cargo:warning=1 error generated.
exit code: 1
--- stderr
error occurred: Command "clang" "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-Wall" "-Wextra" "-g" "-lm" "-Wall" "-o" "/Users/stephanebressani/Code/Rust/yewastrology/target/wasm32-unknown-unknown/debug/build/libswe-sys-2679bddccf8cd805/out/swecl.o" "-c" "/Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.4/src/swisseph/2.08/src/swecl.c" with args "clang" did not execute successfully (status code exit code: 1).
warning: build failed, waiting for other jobs to finish...
你有什么建议?
- 找到一个math.c/math.h文件并将其包含在我的库中c -> rust
- 其他建议???
编辑:
我尝试了两种不起作用的方法:
- 从/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/math.h 在我的 mac 上手动添加 math.h
- 在我的 build.rs 库中添加 .include("/usr/include"(
编译我的libswe-sys的两种方式(0.1.5和0.1.6(
这是红豆杉的日志:
- 使用 0.1.5(手动添加 math.h(
error: failed to run custom build command for `libswe-sys v0.1.5`
--- stdout
TARGET = Some("wasm32-unknown-unknown")
OPT_LEVEL = Some("0")
HOST = Some("x86_64-apple-darwin")
CC_wasm32-unknown-unknown = None
CC_wasm32_unknown_unknown = None
TARGET_CC = None
CC = None
CFLAGS_wasm32-unknown-unknown = None
CFLAGS_wasm32_unknown_unknown = None
TARGET_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("true")
running: "clang" "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-Wall" "-Wextra" "-g" "-Wall" "-o" "/Users/stephanebressani/Code/Rust/yewastrology/target/wasm32-unknown-unknown/debug/build/libswe-sys-b52a4354b3363d0b/out/swedate.o" "-c" "/Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.5/src/swisseph/2.08/src/swedate.c"
running: "clang" "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-Wall" "-Wextra" "-g" "-Wall" "-o" "/Users/stephanebressani/Code/Rust/yewastrology/target/wasm32-unknown-unknown/debug/build/libswe-sys-b52a4354b3363d0b/out/swecl.o" "-c" "/Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.5/src/swisseph/2.08/src/swecl.c"
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.5/src/swisseph/2.08/src/swedate.c:86:
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.5/src/swisseph/2.08/src/swephexp.h:83:
cargo:warning=/Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.5/src/swisseph/2.08/src/sweodef.h:167:10: error: 'math.h' file not found with <angled> include; use "quotes" instead
cargo:warning=#include <math.h>
cargo:warning= ^~~~~~~~
cargo:warning= "math.h"
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.5/src/swisseph/2.08/src/swecl.c:62:
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.5/src/swisseph/2.08/src/swejpl.h:67:
cargo:warning=/Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.5/src/swisseph/2.08/src/sweodef.h:167:10: error: 'math.h' file not found with <angled> include; use "quotes" instead
cargo:warning=#include <math.h>
cargo:warning= ^~~~~~~~
cargo:warning= "math.h"
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.5/src/swisseph/2.08/src/swedate.c:86:
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.5/src/swisseph/2.08/src/swecl.c:62:
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.5/src/swisseph/2.08/src/swejpl.h:67:
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.5/src/swisseph/2.08/src/swephexp.h:83:
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.5/src/swisseph/2.08/src/sweodef.h:167:
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.5/src/swisseph/2.08/src/sweodef.h:167:
cargo:warning=/Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.5/src/swisseph/2.08/src/math.h:295:10: fatal error: '__config' file not found
cargo:warning=#include <__config>
cargo:warning= ^~~~~~~~~~
cargo:warning=/Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.5/src/swisseph/2.08/src/math.h:295:10: fatal error: '__config' file not found
cargo:warning=#include <__config>
cargo:warning= ^~~~~~~~~~
cargo:warning=2 errors generated.
exit code: 1
running: "clang" "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-Wall" "-Wextra" "-g" "-Wall" "-o" "/Users/stephanebressani/Code/Rust/yewastrology/target/wasm32-unknown-unknown/debug/build/libswe-sys-b52a4354b3363d0b/out/swehel.o" "-c" "/Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.5/src/swisseph/2.08/src/swehel.c"
cargo:warning=2 errors generated.
exit code: 1
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.5/src/swisseph/2.08/src/swehel.c:68:
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.5/src/swisseph/2.08/src/swephexp.h:83:
cargo:warning=/Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.5/src/swisseph/2.08/src/sweodef.h:167:10: error: 'math.h' file not found with <angled> include; use "quotes" instead
cargo:warning=#include <math.h>
cargo:warning= ^~~~~~~~
cargo:warning= "math.h"
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.5/src/swisseph/2.08/src/swehel.c:68:
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.5/src/swisseph/2.08/src/swephexp.h:83:
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.5/src/swisseph/2.08/src/sweodef.h:167:
cargo:warning=/Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.5/src/swisseph/2.08/src/math.h:295:10: fatal error: '__config' file not found
cargo:warning=#include <__config>
cargo:warning= ^~~~~~~~~~
cargo:warning=2 errors generated.
exit code: 1
--- stderr
error occurred: Command "clang" "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-Wall" "-Wextra" "-g" "-Wall" "-o" "/Users/stephanebressani/Code/Rust/yewastrology/target/wasm32-unknown-unknown/debug/build/libswe-sys-b52a4354b3363d0b/out/swecl.o" "-c" "/Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.5/src/swisseph/2.08/src/swecl.c" with args "clang" did not execute successfully (status code exit code: 1).
warning: build failed, waiting for other jobs to finish...
error: build failed
error: build failed
- 0.1.6 (在我的 build.rs 库中添加 .include("/usr/include"(
error: failed to run custom build command for `libswe-sys v0.1.6`
--- stdout
TARGET = Some("wasm32-unknown-unknown")
OPT_LEVEL = Some("0")
HOST = Some("x86_64-apple-darwin")
CC_wasm32-unknown-unknown = None
CC_wasm32_unknown_unknown = None
TARGET_CC = None
CC = None
CFLAGS_wasm32-unknown-unknown = None
CFLAGS_wasm32_unknown_unknown = None
TARGET_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("true")
running: "clang" "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-I" "/usr/include" "-Wall" "-Wextra" "-g" "-Wall" "-o" "/Users/stephanebressani/Code/Rust/yewastrology/target/wasm32-unknown-unknown/debug/build/libswe-sys-08f220b2455dd53e/out/swecl.o" "-c" "/Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.6/src/swisseph/2.08/src/swecl.c"
running: "clang" "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-I" "/usr/include" "-Wall" "-Wextra" "-g" "-Wall" "-o" "/Users/stephanebressani/Code/Rust/yewastrology/target/wasm32-unknown-unknown/debug/build/libswe-sys-08f220b2455dd53e/out/swedate.o" "-c" "/Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.6/src/swisseph/2.08/src/swedate.c"
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.6/src/swisseph/2.08/src/swedate.c:86:
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.6/src/swisseph/2.08/src/swephexp.h:83:
cargo:warning=/Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.6/src/swisseph/2.08/src/sweodef.h:167:10: fatal error: 'math.h' file not found
cargo:warning=#include <math.h>
cargo:warning= ^~~~~~~~
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.6/src/swisseph/2.08/src/swecl.c:62:
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.6/src/swisseph/2.08/src/swejpl.h:67:
cargo:warning=/Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.6/src/swisseph/2.08/src/sweodef.h:167:10: fatal error: 'math.h' file not found
cargo:warning=#include <math.h>
cargo:warning= ^~~~~~~~
cargo:warning=1 error generated.
exit code: 1
running: "clang" "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-I" "/usr/include" "-Wall" "-Wextra" "-g" "-Wall" "-o" "/Users/stephanebressani/Code/Rust/yewastrology/target/wasm32-unknown-unknown/debug/build/libswe-sys-08f220b2455dd53e/out/swehel.o" "-c" "/Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.6/src/swisseph/2.08/src/swehel.c"
cargo:warning=1 error generated.
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.6/src/swisseph/2.08/src/swehel.c:68:
cargo:warning=In file included from /Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.6/src/swisseph/2.08/src/swephexp.h:83:
cargo:warning=/Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.6/src/swisseph/2.08/src/sweodef.h:167:10: fatal error: 'math.h' file not found
cargo:warning=#include <math.h>
cargo:warning= ^~~~~~~~
exit code: 1
cargo:warning=1 error generated.
exit code: 1
--- stderr
error occurred: Command "clang" "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-I" "/usr/include" "-Wall" "-Wextra" "-g" "-Wall" "-o" "/Users/stephanebressani/Code/Rust/yewastrology/target/wasm32-unknown-unknown/debug/build/libswe-sys-08f220b2455dd53e/out/swecl.o" "-c" "/Users/stephanebressani/.cargo/registry/src/github.com-1ecc6299db9ec823/libswe-sys-0.1.6/src/swisseph/2.08/src/swecl.c" with args "clang" did not execute successfully (status code exit code: 1).
warning: build failed, waiting for other jobs to finish...
error: build failed
error: build failed
这是我的红豆杉设置(非常小,就像一个hello world项目(:
Cargo.toml
[package]
name = "yewastrology"
version = "0.1.0"
authors = ["stephaneworkspace <s.bressani@bluewin.ch>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
yew = "0.11.0"
astrology = "0.1.24"
src/main.rs
use astrology::{WorkingStorageYew, YewAction, YewAstro};
use yew::{
html, Callback, ClickEvent, Component, ComponentLink, Html, ShouldRender,
};
struct App {
clicked: bool,
onclick: Callback<ClickEvent>,
}
enum Msg {
Click,
}
impl Component for App {
type Message = Msg;
type Properties = ();
fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self {
App {
clicked: false,
onclick: link.callback(|_| Msg::Click),
}
}
fn update(&mut self, msg: Self::Message) -> ShouldRender {
match msg {
Msg::Click => {
self.clicked = true;
true // Indicate that the Component should re-render
},
}
}
fn view(&self) -> Html {
let button_text: String = if self.clicked {
// Ephem file and better path todo later !
let ws = WorkingStorageYew::new(
"/Users/stephanebressani/Code/Rust/yewastrology/data.json",
"",
550,
);
let ok = ws.yew_draw_chart(YewAction::Chart);
let result = ok.0;
result
} else {
"Click me!".to_string()
};
if !self.clicked {
html! {
<button onclick=&self.onclick>{ button_text }</button>
}
} else {
html! {
<h1>{ button_text }</h1>
}
}
}
}
fn main() {
yew::start_app::<App>();
}
和数据.json
{
"year": 1999,
"month": 12,
"day": 31,
"hourf64": 23.59,
"hour": 23,
"min": 59,
"sec": 0.0,
"lat": 46.0222,
"lng": 6.14569
}
对于 0.1.5(手动添加 math.h(源代码不兼容,您是否兼容?
我刚刚在我的mac书上尝试了第一个搜索(搜索结果中的7个在不同的路径中(
编辑 2 :
我发现这个:
https://github.com/rust-lang/libc/issues/858
根据定义,wasm32-unknown-unknown没有libc。如果你想使用 emscripten 或 wasi,你可以使用 wasm32-unknown-emscripten 或 wasm32-wasi,这两者都已经在 libc crate 中得到支持。
我尝试使用emscripter(问题编译,因为我的货物中的库,ansi_term库不兼容(并且wasi与wasm32相同的问题-未知-未知,数学问题.h的问题
你混淆了两件事:-lm
是链接器链接libm.so.6
库的标志;math.h
找不到错误是头文件。
最有可能的是,您的 Linux 盒子上缺少libc6-dev
软件包。
由于您没有提供最小的可重现示例,这是我尝试过的示例,它按预期工作。项目布局:
├── build.rs
├── Cargo.toml
└── src
├── cmath.c
└── main.rs
货物汤姆文件:
[package]
name = "math-ffi"
version = "0.1.0"
authors = ["rustacean"]
edition = "2018"
[dependencies]
libc = "0.2"
[build-dependencies]
cc = "1.0"
build.rs
:
fn main() {
cc::Build::new()
.include("/usr/include") // standard location, YMMV
.flag("-g")
.flag("-Wall")
.file("src/cmath.c")
.compile("math_ffi");
}
C 文件:
#include <math.h>
#define PI 3.14159265
double cos_radian(double x) {
return cos(x * PI / 180);
}
和 Rust 入口点:
use libc::c_double;
extern "C" {
fn cos_radian(_: c_double) -> c_double;
}
fn main() {
let res = unsafe {
cos_radian(180.0)
};
println!("{}", res);
}
它成功构建并正确返回-1
。ldd
显示它应该链接到libm
:
$ ldd target/debug/math-ffi
linux-vdso.so.1 (0x00007ffc60db1000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f8e889e3000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f8e889c0000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f8e889a6000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8e887b5000)
/lib64/ld-linux-x86-64.so.2 (0x00007f8e88a43000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f8e88666000)