It works if you compile bitcode AND the library has the suffic .bc
(e.g. libfoo_core.bc
)!
Emscripten does not link from static library
-
30-06-2022 - |
Question
I have a program I would like to cross compile via Emscripten. So I created a static library foo_core
and now try to link it into a html page via:
$ em++ -std=c++11 -s VERBOSE=1 main.cpp.o -o example.html libfoo_core.js
VERBOSE is on, this generates a lot of output and can slow down compilation
adding ___cxa_atexit and deps atexit
adding _atexit and deps
warning: unresolved symbol: _Z12fooiiii
Now I of course then try to find out why _Z12fooiiii
is missing. In the end doing:
$ grep -r _Z12fooiiii *
example.html: __Z12fooiiii(50, 50, 50, 255);
libfoo_core.js:,0,__Z12fooiiii,0,__ZNSt3__16locale5facetD2Ev,0,__ZTv0_n12_NSt3__113basic_istreamIwNS_11char_traitsIwEEED1Ev,0,__ZNSt3__112system_errorD0Ev
libfoo_core.js:function __Z12fooiiii($r, $g, $b, $a) {
reveals that, the function is actually present in libfoo_core.js
.
So I am pretty confused now and would really appreciate someone explaining to me why this does not work.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow