Create a file GetPrimers.c which has a simple math function.

#include <stdio.h>

// export the function.
#ifdef __EMSCRIPTEN__ 
#include <emscripten.h>
EMSCRIPTEN_KEEPALIVE
#endif
int compute( int a, int b )
{
    int ans = 1;
    for( int i = 0; i < b; ++i )
    {
        ans = ans * a;
    }
    return ans;
}

The declaration EMSCRIPTEN_KEEPALIVE helps us to export the function compute.
Compile the C code to generate an Emscripten plumbing js file and wasm file. EXPORTED_RUNTIME_METHODS tells the compiler that we want to use the runtime functions ccall and cwrap.

emcc GetPrimers.c -o GetPrimers.js -s EXPORTED_RUNTIME_METHODS='["ccall","cwrap"]'

Then add javascript code to use C function compute to get 2^3=8.

All source code has been uploaded to GitHub: exportFunc

Categories: Web

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments

Tex To PDF
: convert the Latex file which suffix is tex to a PDF file

X
0
Would love your thoughts, please comment.x
()
x