Open JarekToro opened 2 years ago
First of all I noticed that you are using the SHELL:
syntax in your target_link_options. However, If you remove the space betwee the -s
and the options name (e.g, -sMAIN_MODULE=2
) then this should not be needed. Unrelated to this issue but should simplify your CMakeLists.txt
.
Regarding the EXPORTED_FUNCTIONS
list, that is indeed a list of C symbol names, which means that if you want to export C++ symbols then you will need to specify the mangled name (i.e. the actual/underlying symbol name).
I think the problem here is that you are using -sSIDE_MODULE=2
to build the side module. If you build the side module instead with just -sSIDE_MODULE
then I think it should solve your problem and all non-hidden symbols will be exported by default.
Thanks appreciate the cmakelist info. I'm relatively new to the c++ world. However the SIDE_MODULE=2 was deliberately set. Geos is a large lib and we only use a small part of it. Also because of licensing we cannot link it statically. When I manually enter all the mangled names the code is reduced to about a third of its size. So Im guessing that's the only solution is to manually find and enter the mangled names? Are there tools to help automate the retrieval of the mangled names?
@JarekToro Hi, could you please share how you get the mangling function names?
@JarekToro Hi, could you please share how you get the mangling function names?
OK, I use llvm-nm, and now I get the function mangling name
Probably better / simple to just export C symbols. You can do that either via EMSCIPTEN_KEEPALIVE
tags on functions in the source, or via extern "C" ..
in the source and EXPORTED_FUNCTIONS
on the command line.
Exporting C++ functions directly is almost never desirable IIUC.
Probably better / simple to just export C symbols. You can do that either via
EMSCIPTEN_KEEPALIVE
tags on functions in the source, or viaextern "C" ..
in the source andEXPORTED_FUNCTIONS
on the command line.Exporting C++ functions directly is almost never desirable IIUC.
Thanks for your reply. However, currently we are working on a big commercial C++ project, add extern "C" or EMSCIPTEN_KEEPALIVE
seems not quite possible.
Can I ask why are you trying to export the C++ functions? Are you trying to call them directly from JS? Don't your need somethink like embind if you want to acheive this?
Another option is to great a new wasm_exports.cpp
file in your project and then export the C symbols that you need.
e.g. :
extern "C" {
xxx SimpleStrTree(yyy) {
return geos::index::srttree::SimpleStrTree();
}
}
No need to modify the original source then.
Still it begs the question as to who you are going construct the arguments or use the return values form JS (without something like embind).
We want to generate a sharable wasm file that includes specific cpp functions. As we do not want those function which not in the specific list to be included in the sharable file, I try to use SIDE_MODULE=2
and EXPORTED_FUNCTIONS
to achieve this goal.
Simply speaking, I want to achieve that multiple web apps can share a common wasm on my device, and the common wasm should include a specific function list. So I tried SIDE_MODULE
and EXPORTED_FUNCTIONS
to see if they can cooperate to realize my goal. Can I get any suggestions?
Who is going to be calling the function in the this "common wasm".
Emscripten does support multiple main modules calling into a shared side module, so if that works for you I would use the MAIN_MODULE=2
/ SIDE_MODULE=2
system.
Normally you would contol which which symbols are import/exported via __attribute__((visibility))
in the source code, but if you can't modify the source code and its doesn't currently contain the correct visibility
attributes when yes you will end up needing to using -sEXPORTED_FUNCTIONS
. I recommend using using -sEXPORTED_FUNCTIONS=@filename.txt
and listing you exports one per line in that file.
We only support mangled names in the EXPORTED_FUNCTIONS
list I'm afraid, and I don't think we want to try to change that at this point.
Thank you very much for all your kind reply and suggestions :) I will get a try
Please include the following in your bug report:
Version of emscripten/emsdk:
Failing command line in full:
While
SimpleStrTree
is exported.This is thrown because of the name mangling.
If I Manually Add
__ZTVN4geos5index7strtree13SimpleSTRtreeE
to the exportedEXPORTED_FUNCTIONS
it works as expected.