我目前正在使用 C 和 Rust 开发一个应用程序,当它以下列任何一种方式使用时,我都没有任何问题:
- C -> Rust -> C (swift)
- C -> Rust -> 示例(控制台 Rust)
但是当我想通过 Yew 中的 wasm 访问时,它变得越来越复杂
- C -> Rust -> Yew/WASM (cargo web start)
链接器抛出错误:缺少“math.h”
维基百科引用:https ://en.wikipedia.org/wiki/C_mathematical_functions
在 Linux 和 BSD 下,数学函数(如 中声明的)分别捆绑在数学库 libm 中。因此,如果使用这些函数中的任何一个,则必须为链接器提供指令 -lm。
虽然我添加了标志,但它并没有改变任何东西......
下面我包含了build.rs
来自我的库文件绑定 C -> Rust 的文件:
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")
}
这是我在 yew (cargo web start) 中编译的错误日志
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
- 其他建议???
编辑:
我尝试了两种不起作用的方法:
- 在我的 Mac 上从 /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/math.h 手动添加一个 math.h
- 在我的库的 build.rs 中添加 .include("/usr/include")
这两种方式编译我的 libswe-sys(0.1.5 和 0.1.6)
这是 wasm 的 yew 日志:
- 使用 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
这是我的 yew 设置(非常小,就像一个 hello world 项目):
货运.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>();
}
和 data.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 book 上的搜索中尝试了第一个(7 在不同路径的搜索结果中)
编辑 2:
我找到了这个 :
https://github.com/rust-lang/libc/issues/858
根据定义,wasm32-unknown-unknown 没有 libc。如果您想使用 emscripten 或 wasi,您可以使用 wasm32-unknown-emscripten 或 wasm32-wasi,这两种方法都已在 libc crate 中得到支持。
我尝试使用 emscripter (问题编译,因为我的货物中的 lib、ansi_term 库是不兼容的)和 wasi 与 wasm32-unknown-unknown 相同的问题,math.h 的问题