'emscripten undefined exported function:
I'm stuck and I hope somebody can help, I am trying to build the h264lib_opencore library to webasm and I successfully built it, I isolated the functions that I need from this massive library and its dependencies that I need and built a .a library from it thru either emmake make, or setting up the toolchain in CLion, it can successfully built static library .a from emscripten toolchain.
However, I don’t think the functions are exported properly so I used the -s EXPORTED_FUNCTIONS
command but unfortunately I am getting undefined exported functions even though I already added a EMSCRIPTEN_KEEPALIVE
to the function I'm trying to call.
And that function can also be seen in the generated .a file (thru hex editor).
But when I do emcc
(or em++
) with -s EXPORTED_FUNCTIONS
I'm getting an error “undefined exported functions”
What else I am missing here?
the command I used:
em++ libH264lib_opencore.a -o H264lib_opencore.js -s EXPORTED_FUNCTIONS="['_h264_decoder_process_first_frame']"
error
em++: error: undefined exported function: "_h264_decoder_process_first_frame" [-Wundefined] [-Werror]
and if I open hexeditor for the generated .a library, I can see that the function is in there, although named like something like
_ZN16h264lib_opencore32h264_decoder_process_first_frameEPvS0_iS0_iPiS1_i
I also added int EMSCRIPTEN_KEEPALIVE h264_decoder_process_first_frame()
in the source before compiling
What am I missing here?
Solution 1:[1]
extern "C" : prevent function names from being mangled when compiled so that your JavaScript code can use the expected function name
Solution 2:[2]
I've got an answer for everybody's reference;
since the file is in CPP, I just need to put extern "C" {}
to the functions I am exporting and it will work!
So in this case if I am exporting a function h264_decoder_process_first_frame
I need to do in header file
extern "C" {
void h264_decoder_process_first_frame();
}
and it can be exported now.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Praveer Kumar |
Solution 2 | Tim Sylvester |