As I start delving into Emscripten, I've encountered a puzzling issue with exporting functions for use in JavaScript. Working on a test project involving libsquish, the specific details aren't crucial to my question beyond the header/code filenames.
So, to simplify the test,
c/c++
//squish.h
extern "C" int main();
int main();
extern "C" int gsr();
int gsr();
//squish.cpp
int main()
{
return 99;
}
int gsr()
{
return 8675309;
}
Additional Options/Command Line
-s EXPORTED_FUNCTIONS="['_gsr','_main']"
Javascript
main=Module.cwrap('main','number',null);
console.log(main());
GetStorageRequirements = Module.cwrap('gsr', 'number',null);
console.log(GetStorageRequirements());
Javascript Console (Chrome)
99
Assertion failed: Cannot call unknown function gsr (perhaps LLVM optimizations or closure removed it?)
Assertion failed: Cannot call unknown function gsr (perhaps LLVM optimizations or closure removed it?)
Furthermore, optimization is disabled (O0).
So, why is one function recognized while the others are deemed "unknown"? Despite sharing similar characteristics, it appears that the EXPORTED_FUNCTIONS directive is being disregarded. The only plausible explanation is that the 'main' function is automatically exported, causing the confusion.