emscripten

Passing double arrays between functions in asm.js

冷暖自知 提交于 2019-12-02 01:58:18
问题 I have a C function compiled into asm.js with the following parameters: void myfunc(double v1[], double v2[], int v_size, double c) It takes in an array ( v1 ), applies a transformation, then fills another array of the same size ( v2 ) with the output. I compile it, and then run the following JS code: v1 = new Array(1.0, 1.5, 2.0); v2 = Module._malloc(8 * v1.length); Module.ccall("myfunc", null, ["array", "number", "number", "number"], [v1, v2, v1.length, 2]); However when I run getValue(v2,

Passing double arrays between functions in asm.js

坚强是说给别人听的谎言 提交于 2019-12-02 01:18:48
I have a C function compiled into asm.js with the following parameters: void myfunc(double v1[], double v2[], int v_size, double c) It takes in an array ( v1 ), applies a transformation, then fills another array of the same size ( v2 ) with the output. I compile it, and then run the following JS code: v1 = new Array(1.0, 1.5, 2.0); v2 = Module._malloc(8 * v1.length); Module.ccall("myfunc", null, ["array", "number", "number", "number"], [v1, v2, v1.length, 2]); However when I run getValue(v2, "double") I get 1.297703e-318 (which is wrong), and when I run getValue(v2 + 8, "double") or getValue

Linking OpenSSL with webassembly

守給你的承諾、 提交于 2019-12-01 23:29:23
Linking OpenSSL to webassembly Before asking this question I just want to say that I did some homework. The question is very similar to the one already asked here i.e. How to link OpenSSL with emscripten? After I found a very good and detail manual how to compile OpenSSL to webassemly here https://www.ip6.li/node/129 I was able to run all steps successfully i.e. 1) first go to the directory where the latest emscripten is downloaded and set some path variables: ~/emscripten/emsdk$ source ./emsdk_env.sh 2) then execute the script from the manual above ./mk-openssl-webassemby.sh: Basically, it

Using emscripten how to get C++ uint8_t array to JS Blob or UInt8Array

别说谁变了你拦得住时间么 提交于 2019-12-01 09:24:48
问题 In emscripten C++, I have class MyClass { public: MyClass() {} std::shared_ptr<std::vector<uint8_t>> buffer; int getPtr() { return (int)(buffer->data()); } int getLength() { return buffer->size(); } }; EMSCRIPTEN_BINDINGS() { class_<MyClass>("MyClass").constructor() .function("getLength",&MyClass::getLength) .function("getPtr",&MyClass::getPtr, allow_raw_pointers()); } I can invoke getLength() and getPtr() from JS but I'm don't know how to get JS to treat it as an ArrayBuffer for download as

Struct operations in Javascript through Emscripten

与世无争的帅哥 提交于 2019-12-01 00:40:44
I am having quite a lot of problems with emscripten inter-operating between C and Javascript. More specifically, I am having trouble accessing a struct created in C in javascript, given that the pointer to the struct is passed into javascript as an external library . Take a look at the following code: C: #include <stdlib.h> #include <stdio.h> #include <inttypes.h> struct test_st; extern void read_struct(struct test_st *mys, int siz); struct test_st{ uint32_t my_number; uint8_t my_char_array[32]; }; int main(){ struct test_st *teststr = malloc(sizeof(struct test_st)); teststr->my_number = 500;

emscripten: How can I solve UnboundTypeError

一世执手 提交于 2019-11-30 20:45:25
I am trying to build with emscripten a program which uses std::vector and std::map and the compilation is successful. However, when I ran it on the web browser(firefox/chrome), UnboundTypeError was catched. [03:21:26.453] UnboundTypeError: Cannot call intArrayToVector due to unbound types: Pi Here is c++ code and HTML file which uses generated javascript code. test.cpp: #include <vector> #include <emscripten/bind.h> using namespace emscripten; std::vector<int> intArrayToVector(int* input, int num){ std::vector<int> vec; for(int i=0; i<num; i++){ int val = *(input+i); vec.push_back(val); }

Struct operations in Javascript through Emscripten

强颜欢笑 提交于 2019-11-30 19:49:52
问题 I am having quite a lot of problems with emscripten inter-operating between C and Javascript. More specifically, I am having trouble accessing a struct created in C in javascript, given that the pointer to the struct is passed into javascript as an external library. Take a look at the following code: C: #include <stdlib.h> #include <stdio.h> #include <inttypes.h> struct test_st; extern void read_struct(struct test_st *mys, int siz); struct test_st{ uint32_t my_number; uint8_t my_char_array[32

How to link OpenSSL with emscripten?

纵然是瞬间 提交于 2019-11-30 18:59:45
问题 I'm trying to compile some C code that uses OpenSSL with emscripten, but I get unresolved symbol warnings like: warning: unresolved symbol: SHA256_Init warning: unresolved symbol: SHA256_Final warning: unresolved symbol: SHA256_Update I compiled the code using this command: emcc SHA256.c -lssl -lcrypto -L /usr/local/openssl-1.0.2k/lib/ -I /usr/local/openssl-1.0.2k/include -s WASM=1 -o SHA256.html --emrun With the following source code #include <stdio.h> #include <string.h> #include <stdlib.h>

Can I read files from the disk by using Webassembly?

空扰寡人 提交于 2019-11-30 17:18:23
I followed the Webassembly getting started tutorial http://webassembly.org/getting-started/developers-guide/ It worked fine and displayed the "Hello, world!" message in the browser. Then I tried a small C++ code, that opens a text file and does the calculation (10 * 20) after reading the file. emcc compiled the file just fine, no errors. But when I serve the file over HTTP by running emrun, it cannot open the file. This is what I see in the emrun web console: Unable to open file 200 Is there any restrictions to open files from the local disk? [thiago@terra hello]$ cat pfile.cpp #include

Use Emscripten with Fortran: LAPACK binding

ⅰ亾dé卋堺 提交于 2019-11-30 15:07:07
My goal is to use LAPACK with Emscripten. My question is: how to port LAPACK to JS? The are two ways I can think of: CLAPACK to JS where my question is: does anybody know an unofficial version that is later than 3.2.1? And the other way to think of is: how to port FORTRAN to JS? Emscripten is capable of transforming C code to JavaScript. But unfortunately, LAPACK 3.5.0 ( http://www.netlib.org/lapack/ ) is only available in FORTRAN95. The CLAPACK project ( http://www.netlib.org/clapack/ ) is basically what I want: a C version of LAPACK. But this one is outdated; the latest is 3.2.1. F2C only