Skip to content

Instantly share code, notes, and snippets.

@xxuejie
Created January 1, 2013 18:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xxuejie/4429142 to your computer and use it in GitHub Desktop.
Save xxuejie/4429142 to your computer and use it in GitHub Desktop.
Module.ccall also does not work in asm.js
#include <stdio.h>
#include <emscripten/emscripten.h>
int EMSCRIPTEN_KEEPALIVE c_func_calling_from_js() {
printf("This is a c function calling from js!");
return 0;
}
extern void js_func();
int main(int argc, char *argv[])
{
js_func();
return 0;
}
mergeInto(LibraryManager.library, {
js_func: function() {
Module.print("Now we are in js side, let's call back to c side!");
Module.ccall('c_func_calling_from_js', 'number', [], []);
}
});
$ emcc --js-library asmjs-test.js asmjs-test.c -s ASM_JS=1
$ node a.out.js
Now we are in js side, let's call back to c side!
Assertion failed: Cannot call unknown function c_func_calling_from_js (perhaps LLVM optimizations or closure removed it?):
Error
at abort (/Users/rafael/develop/tmp/asmjs/a.out.js:491:32)
at assert (/Users/rafael/develop/tmp/asmjs/a.out.js:498:5)
at getCFunc (/Users/rafael/develop/tmp/asmjs/a.out.js:543:56)
at Object.ccall (/Users/rafael/develop/tmp/asmjs/a.out.js:530:20)
at _js_func (/Users/rafael/develop/tmp/asmjs/a.out.js:1929:14)
at Object._main (/Users/rafael/develop/tmp/asmjs/a.out.js:2445:8)
at Object.callMain (/Users/rafael/develop/tmp/asmjs/a.out.js:2542:25)
at doRun (/Users/rafael/develop/tmp/asmjs/a.out.js:2574:20)
at run (/Users/rafael/develop/tmp/asmjs/a.out.js:2598:12)
at /Users/rafael/develop/tmp/asmjs/a.out.js:2620:13
/Users/rafael/develop/tmp/asmjs/a.out.js:493
throw "Assertion: " + text;
^
Assertion: Assertion failed: Cannot call unknown function c_func_calling_from_js (perhaps LLVM optimizations or closure removed it?)
$ emcc --js-library asmjs-test.js asmjs-test.c
$ node a.out.js
Now we are in js side, let's call back to c side!
This is a c function calling from js!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment