wasm-ld:错误:初始内存太小,需要18317952字节

问题描述

我想将ffmpeg编译为wasm。下载FFMPEG和emsdk源代码后,我使用下面的命令进行构建。

emconfigure   ./configure --cc="emcc" --enable-cross-compile --target-os=none --arch=x86_32 --cpu=generic \
--disable-ffplay --disable-ffprobe --disable-asm --disable-doc --disable-devices --disable-pthreads --disable-w32threads --disable-network \
--disable-hwaccels --disable-parsers --disable-bsfs --disable-debug --disable-protocols --disable-indevs --disable-outdevs --enable-protocol=file  --ranlib="emranlib" 

emmake make

然后我得到了这样的错误

emcc: warning: ignoring unsupported linker flag: `-rpath-
link=:libpostproc:libswresample:libswscale:libavfilter:libavdevice:libavfo
rmat:libavcodec:libavutil:libavresample` [-Wlinkflags]
wasm-ld: error: initial memory too small,18317952 bytes needed
emcc: error: '/home/ubuntu/emsdk/upstream/bin/wasm-ld -o 
/tmp/emscripten_temp_t3l4sg_k/ffmpeg_g.wasm -Llibavcodec -Llibavdevice 
-Llibavfilter -Llibavformat -L/home/ubuntu/emsdk/upstream/emscripten
/system/local/lib -Llibavresample -L/home/ubuntu/emsdk/upstream/emscripten
/system/lib -Llibavutil -L/home/ubuntu/emsdk/upstream/emscripten
/cache/wasm -Llibpostproc -Llibswscale -Llibswresample -z noexecstack 
fftools/ffmpeg_opt.o fftools/ffmpeg_filter.o fftools/ffmpeg_hw.o 
fftools/cmdutils.o fftools/ffmpeg.o libavdevice/libavdevice.a 
libavfilter/libavfilter.a libavformat/libavformat.a 
libavcodec/libavcodec.a libswresample/libswresample.a 
libswscale/libswscale.a libavutil/libavutil.a /home/ubuntu/emsdk/upstream
/emscripten/cache/wasm/libc.a /home/ubuntu/emsdk/upstream/emscripten/cache
/wasm/libcompiler_rt.a /home/ubuntu/emsdk/upstream/emscripten/cache
/wasm/libc++-noexcept.a /home/ubuntu/emsdk/upstream/emscripten/cache
/wasm/libc++abi-noexcept.a /home/ubuntu/emsdk/upstream/emscripten/cache
/wasm/libdlmalloc.a /home/ubuntu/emsdk/upstream/emscripten/cache
/wasm/libpthread_stub.a /home/ubuntu/emsdk/upstream/emscripten/cache
/wasm/libc_rt_wasm.a /home/ubuntu/emsdk/upstream/emscripten/cache
/wasm/libsockets.a -mllvm -combiner-global-alias-analysis=false -mllvm 
-enable-emscripten-sjlj -mllvm -disable-lsr --allow-undefined --import-
memory --import-table --strip-debug --export main --export malloc --export 
free --export stackSave --export stackRestore --export stackalloc --export 
__data_end --export __wasm_call_ctors --export fflush --export 
__errno_location --export _get_tzname --export _get_daylight --export 
_get_timezone --export memalign --export memset -z stack-size=5242880 
--initial-memory=16777216 --no-entry --max-memory=16777216 --global-base=1024' Failed

如何更改认的emcc 初始内存设置?

解决方法

github issue中有一个答案。

最快的解决方法是将总内存标志设置为 -s TOTAL_MEMORY=num_bytes。只需确保您传递的数字是 64kb 的倍数,否则将无法编译。

此外,如果您打算更改代码库,我会四舍五入,因为“所需字节数”的大小可能会发生变化,在我的情况下,它受 60MB 的限制(对于与此无关的代码)。