1
votes

im 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 sucessfuly 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 Im 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 im 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?

2

2 Answers

1
votes

ive 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.

1
votes

extern "C" : prevent function names from being mangled when compiled so that your JavaScript code can use the expected function name