emscripten-core / emscripten-core/emscripten

Bug about export C++ to Es6

Open
#21,160 5 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

I compiled my c++ code into an ES6 module through Emscripten, but after I imported it via "import", when I ran npm run build, it kept showing out of memory, I tried to increase the memory, but no matter how big I increased, it always reported an error exceeding memory, my compilation settings are as follows, what should I do to solve this problem?

This is the setting of the cmakelist.txt for the entire project:

```
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3 -Wall -fPIC -pthread ")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_PTHREADS=1 -fexceptions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s MODULARIZE=1 -s EXPORT_ES6=1 -s USE_ES6_IMPORT_META=1")
set(CMAKE_CXX_STANDARD 11)
add_definitions(-DWASM_JS)
```

This is the setting for the submodule's cmakelist.txt:

```
set(EMSCRIPTEN_LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS} -O3 -s MODULARIZE=1 -s SINGLE_FILE=0 -s EXPORT_NAME='MTMP' -s DEMANGLE_SUPPORT=1")
set(EMSCRIPTEN_LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS} -pthread -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=4 -s ASYNCIFY -s ASSERTIONS -s PTHREAD_POOL_SIZE_STRICT=0 ")
set(EMSCRIPTEN_LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS} -sSTACK_SIZE=10485760 --memory-init-file 0 -s TOTAL_MEMORY=256MB -s WASM_MEM_MAX=1GB -s ALLOW_MEMORY_GROWTH=1 ")
set(EMSCRIPTEN_LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS} -s EXPORT_EXCEPTION_HANDLING_HELPERS -fexceptions ")
set(EMSCRIPTEN_LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS} --bind -s EXPORTED_RUNTIME_METHODS=['ccall','getValue','setValue','cwrap'] ")
set(EMSCRIPTEN_LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS} -o ${js_name}.js")
set_target_properties(${js_name} PROPERTIES LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS}")
```

The following error message is displayed:

![image](https://github.com/emscripten-core/emscripten/assets/49711774/586adb68-ecab-48e0-b5b7-9076b8470882)

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.