Giter Site home page Giter Site logo

c-in-rust-with-wasm-pack's Introduction

C/C++ in Rust compiled with wasm-pack issue

I am trying to include C++ code in my rust code. This repository shows how I'm currently trying to do so. If you have a better solution please tell me!

Error

When compiling with wasm-pack I get the following message:

user@ubuntu:~/c-in-rust-with-wasm-pack$ wasm-pack build
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
   Compiling c-in-rust-with-wasm-pack v0.1.0 (/home/user/c-in-rust-with-wasm-pack)
error[E0425]: cannot find function `add_one` in this scope
  --> src/lib.rs:25:52
   |
25 |     alert(format!("Evaluating {}!", unsafe { add_one(1) }).as_str());
   |                                              ^^^^^^^ not found in this scope

For more information about this error, try `rustc --explain E0425`.
error: could not compile `c-in-rust-with-wasm-pack` due to previous error
Error: Compiling your crate to WebAssembly failed
Caused by: failed to execute `cargo build`: exited with exit status: 101
  full command: "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown"

Prerequisites

This example is using cc-rs which has some requirements seen here. For Linux clang is required and can be installed using:

sudo apt-get install clang

wasm-pack is also needed and can be installed with:

cargo install wasm-pack

Run

wasm-pack build

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.