emscripten-core / emscripten-core/emscripten

Unable to export c++ functions via EXPORTED_FUNCTIONS as they get namemangled and are unrecognized.

Open
#15,841 11 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Please include the following in your bug report:

**Version of emscripten/emsdk:**
```sh
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.0.0-git (3fd52e107187b8a169bb04a02b9f982c8a075205)
clang version 14.0.0 (/srcdest/llvm-project 4348cd42c385e71b63e5da7e492172cff6a79d7b)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /opt/emscripten-llvm/bin
```

**Failing command line in full:**
```cmake

target_compile_options(geos PRIVATE
-fPIC
--no-entry
"SHELL:-s SIDE_MODULE=2")

target_link_options(geos PRIVATE
"SHELL:-s LLD_REPORT_UNDEFINED=1"
"SHELL:-s EXPORT_ALL=1"
"SHELL:-s FILESYSTEM=0"
"SHELL:-s WASM=1"
"SHELL:-s EXPORTED_FUNCTIONS=['geos::index::srttree::SimpleStrTree']"
"SHELL:-s WASM_BIGINT=1"
"SHELL:-s SIDE_MODULE=2")

target_link_libraries(main_program PRIVATE geos)

target_compile_options(main_program PRIVATE -fPIC "SHELL:-s MAIN_MODULE=2")

target_link_options(
main_program
PRIVATE
--no-entry
--bind
"SHELL:-s LLD_REPORT_UNDEFINED=1"
"SHELL:-s MAIN_MODULE=2"
"SHELL:-s ENVIRONMENT=web"
"SHELL:-s WASM=1"
"SHELL:-s WASM_BIGINT=1"
"SHELL:-s MODULARIZE=1"
"SHELL:-s ALLOW_MEMORY_GROWTH=1"
"SHELL:-s FILESYSTEM=0"
"SHELL:-s USE_ES6_IMPORT_META=1"
"SHELL:-s EXPORT_ES6=1"
"SHELL: -s USE_CLOSURE_COMPILER=1"
"SHELL:-s EXPORT_NAME=\"MainProgram\""
)

```

While `SimpleStrTree` is exported.

This is thrown because of the name mangling.

```
error: undefined symbol: _ZTVN4geos5index7strtree13SimpleSTRtreeE (referenced by top-level compiled C/C++ code)
warning: __ZTVN4geos5index7strtree13SimpleSTRtreeE may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
```

If I Manually Add `__ZTVN4geos5index7strtree13SimpleSTRtreeE` to the exported `EXPORTED_FUNCTIONS` it works as expected.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.