Open duanyuanyuan123 opened 1 year ago
I have also encountered it. Do you know how to solve it? My computer is Mac OS m2
build-emscripten.sh
#!/bin/bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [[ $# -ne 1 ]] ; then
echo "Usage: $0 SRCDIR"
echo
echo "It is recommended to build in a separate directory."
echo "Then specify this directory as an argument to this script."
echo "Example:"
echo " mkdir buildjs"
echo " cd buildjs"
echo " USE_WASM=0 ../build-emscripten.sh .."
echo
echo "This should generate a libheif.js and (optionally, without the USE_WASM=0) a libheif.wasm"
exit 5
fi
SRCDIR=$1
# CORES="${CORES:-`nproc --all`}"
CORES="${CORES:-`sysctl -n hw.logicalcpu | awk '{print $1}'`}"
ENABLE_LIBDE265="${ENABLE_LIBDE265:-1}"
LIBDE265_VERSION="${LIBDE265_VERSION:-1.0.12}"
ENABLE_AOM="${ENABLE_AOM:-0}"
AOM_VERSION="${AOM_VERSION:-3.6.1}"
STANDALONE="${STANDALONE:-0}"
DEBUG="${DEBUG:-0}"
USE_WASM="${USE_WASM:-1}"
echo "Build using ${CORES} CPU cores"
LIBRARY_LINKER_FLAGS=""
LIBRARY_INCLUDE_FLAGS=""
CONFIGURE_ARGS_LIBDE265=""
if [ "$ENABLE_LIBDE265" = "1" ]; then
[ -s "libde265-${LIBDE265_VERSION}.tar.gz" ] || curl \
-L \
-o libde265-${LIBDE265_VERSION}.tar.gz \
https://github.com/strukturag/libde265/releases/download/v${LIBDE265_VERSION}/libde265-${LIBDE265_VERSION}.tar.gz
if [ ! -s "libde265-${LIBDE265_VERSION}/libde265/.libs/libde265.so" ]; then
tar xf libde265-${LIBDE265_VERSION}.tar.gz
cd libde265-${LIBDE265_VERSION}
[ -x configure ] || ./autogen.sh
CXXFLAGS=-O3 emconfigure ./configure --disable-sse --disable-dec265 --disable-sherlock265
emmake make -j${CORES}
cd ..
fi
CONFIGURE_ARGS_LIBDE265="-DLIBDE265_INCLUDE_DIR=${DIR}/libde265-${LIBDE265_VERSION} -DLIBDE265_LIBRARY=-L${DIR}/libde265-${LIBDE265_VERSION}/libde265/.libs"
LIBRARY_LINKER_FLAGS="$LIBRARY_LINKER_FLAGS -lde265"
LIBRARY_INCLUDE_FLAGS="$LIBRARY_INCLUDE_FLAGS -L${DIR}/libde265-${LIBDE265_VERSION}/libde265/.libs"
fi
CONFIGURE_ARGS_AOM=""
if [ "$ENABLE_AOM" = "1" ]; then
[ -s "aom-${AOM_VERSION}.tar.gz" ] || curl \
-L \
-o aom-${AOM_VERSION}.tar.gz \
"https://aomedia.googlesource.com/aom/+archive/v${AOM_VERSION}.tar.gz"
if [ ! -s "aom-${AOM_VERSION}/libaom.a" ]; then
mkdir -p aom-${AOM_VERSION}/aom-source
tar xf aom-${AOM_VERSION}.tar.gz -C aom-${AOM_VERSION}/aom-source
cd aom-${AOM_VERSION}
emcmake cmake aom-source \
-DENABLE_CCACHE=1 \
-DAOM_TARGET_CPU=generic \
-DENABLE_DOCS=0 \
-DENABLE_TESTS=0 \
-DENABLE_EXAMPLES=0 \
-DENABLE_TESTDATA=0 \
-DENABLE_TOOLS=0 \
-DCONFIG_MULTITHREAD=0 \
-DCONFIG_RUNTIME_CPU_DETECT=0 \
-DBUILD_SHARED_LIBS=1 \
-DCMAKE_BUILD_TYPE=Release
emmake make -j${CORES}
cd ..
fi
CONFIGURE_ARGS_AOM="-DAOM_INCLUDE_DIR=${DIR}/aom-${AOM_VERSION}/aom-source -DAOM_LIBRARY=-L${DIR}/aom-${AOM_VERSION}"
LIBRARY_LINKER_FLAGS="$LIBRARY_LINKER_FLAGS -laom"
LIBRARY_INCLUDE_FLAGS="$LIBRARY_INCLUDE_FLAGS -L${DIR}/aom-${AOM_VERSION}"
fi
EXTRA_EXE_LINKER_FLAGS="-lembind"
EXTRA_COMPILER_FLAGS=""
if [ "$STANDALONE" = "1" ]; then
EXTRA_EXE_LINKER_FLAGS=""
EXTRA_COMPILER_FLAGS="-D__EMSCRIPTEN_STANDALONE_WASM__=1"
fi
CONFIGURE_ARGS="-DENABLE_MULTITHREADING_SUPPORT=OFF -DWITH_GDK_PIXBUF=OFF -DWITH_EXAMPLES=OFF -DBUILD_SHARED_LIBS=ON -DENABLE_PLUGIN_LOADING=OFF"
emcmake cmake ${SRCDIR} $CONFIGURE_ARGS \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_FLAGS="${EXTRA_COMPILER_FLAGS}" \
-DCMAKE_CXX_FLAGS="${EXTRA_COMPILER_FLAGS}" \
-DCMAKE_EXE_LINKER_FLAGS="${LIBRARY_LINKER_FLAGS} ${EXTRA_EXE_LINKER_FLAGS}" \
$CONFIGURE_ARGS_LIBDE265 \
$CONFIGURE_ARGS_AOM
VERBOSE=1 emmake make -j${CORES}
LIBHEIFA="libheif/libheif.a"
EXPORTED_FUNCTIONS=$($EMSDK/upstream/bin/llvm-nm $LIBHEIFA --format=just-symbols | grep "^heif_\|^de265_\|^aom_" | grep "[^:]$" | sed 's/^/_/' | paste -sd "," -)
echo "Running Emscripten..."
BUILD_FLAGS="-lembind -o libheif.js --pre-js ${SRCDIR}/pre.js --post-js ${SRCDIR}/post.js -sWASM=$USE_WASM"
RELEASE_BUILD_FLAGS="-O3"
if [ "$STANDALONE" = "1" ]; then
# Note: this intentionally overwrites the BUILD_FLAGS set above
echo "Building in standalone (non-web) build mode"
BUILD_FLAGS="-s STANDALONE_WASM=1 -s WASM=1 -o libheif.wasm --no-entry"
fi
if [ "$DEBUG" = "1" ]; then
echo "Building in debug mode"
RELEASE_BUILD_FLAGS="--profile -g"
fi
emcc "$LIBHEIFA" \
-s EXPORTED_FUNCTIONS="$EXPORTED_FUNCTIONS,_free,_malloc,_memcpy" \
-s ALLOW_MEMORY_GROWTH=1 \
-s ERROR_ON_UNDEFINED_SYMBOLS=0 \
-s LLD_REPORT_UNDEFINED \
--memory-init-file 0 \
-std=c++11 \
$LIBRARY_INCLUDE_FLAGS \
$LIBRARY_LINKER_FLAGS \
$BUILD_FLAGS \
$RELEASE_BUILD_FLAGS
cache:INFO: generating system asset: symbol_lists/f0d44eb54c77f4a73d9184c637536d1fdd49275a.json... (this will be cached in "/Users/usename/project/emsdk/upstream/emscripten/cache/symbol_lists/f0d44eb54c77f4a73d9184c637536d1fdd49275a.json" for subsequent builds)
cache:INFO: - ok
wasm-ld: error: unknown argument: -flat_namespace
em++: error: '/Users/usename/project/emsdk/upstream/bin/wasm-ld -o .libs/libde265.0.wasm -flat_namespace -undefined suppress .libs/libde265.0.dylib-master.o -L/Users/usename/project/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten -lGL -lal -lhtml5 -lstubs -lnoexit -lc -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr /var/folders/zk/g2crrhzj0fz5wt65mpvb7tnc0000gn/T/tmpppp0iu5vlibemscripten_js_symbols.so --strip-debug --export-if-defined=main --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=__main_argc_argv --export=stackSave --export=stackRestore --export=stackAlloc --export=__errno_location --export=__get_temp_ret --export=__set_temp_ret --export=__wasm_call_ctors --export-table -z stack-size=65536 --initial-memory=16777216 --max-memory=16777216 --no-entry --table-base=1 --global-base=1024' failed (returned 1)
make[3]: *** [libde265.la] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
emmake: error: 'make -j10' failed (returned 2)
username@192 buildjs % emcc -v
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.46 (19607820c447a13fd8d0b7680c56148427d6e1b8)
clang version 18.0.0 (https://github.com/llvm/llvm-project 75501f53624de92aafce2f1da698b249a7293dc7)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /Users/username/project/emsdk/upstream/bin
Can you check if these changes to build-emscripten fix it for you? (probably best to remove the libde265-* folder before you try this.)
diff --git a/build-emscripten.sh b/build-emscripten.sh
index 2648c6e..bc43f42 100755
--- a/build-emscripten.sh
+++ b/build-emscripten.sh
@@ -38,11 +38,11 @@ if [ "$ENABLE_LIBDE265" = "1" ]; then
-L \
-o libde265-${LIBDE265_VERSION}.tar.gz \
https://github.com/strukturag/libde265/releases/download/v${LIBDE265_VERSION}/libde265-${LIBDE265_VERSION}.tar.gz
- if [ ! -s "libde265-${LIBDE265_VERSION}/libde265/.libs/libde265.so" ]; then
+ if [ ! -s "libde265-${LIBDE265_VERSION}/libde265/.libs/libde265.a" ]; then
tar xf libde265-${LIBDE265_VERSION}.tar.gz
cd libde265-${LIBDE265_VERSION}
[ -x configure ] || ./autogen.sh
- CXXFLAGS=-O3 emconfigure ./configure --disable-sse --disable-dec265 --disable-sherlock265
+ CXXFLAGS=-O3 emconfigure ./configure --disable-sse --disable-dec265 --disable-sherlock265 --enable-shared=off
emmake make -j${CORES}
cd ..
fi
wasm-ld: error: unknown argument: -flat_namespace em++: error: '/Users/duanyuanyuan/Documents/worker/baidu/bce-multimedia/emsdk/upstream/bin/wasm-ld -o .libs/libde265.0.wasm -flat_namespace -undefined suppress .libs/libde265.0.dylib-master.o -L/Users/duanyuanyuan/Documents/worker/baidu/bce-multimedia/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten -lGL -lal -lhtml5 -lstubs -lnoexit -lc -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr /var/folders/xf/zkhyhm5d32j3r51_y6kbcxdm0000gn/T/tmpl3gk8b1nlibemscripten_js_symbols.so --strip-debug --export-if-defined=main --export-if-defined=start_em_asm --export-if-defined=stop_em_asm --export-if-defined=start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=start_em_js --export-if-defined=stop_em_js --export-if-defined=main_argc_argv --export=stackSave --export=stackRestore --export=stackAlloc --export=__errno_location --export=get_temp_ret --export=set_temp_ret --export=__wasm_call_ctors --export-table -z stack-size=65536 --initial-memory=16777216 --no-entry --max-memory=16777216 --global-base=1024' failed (returned 1) make[3]: [libde265.la] Error 1 make[2]: [all-recursive] Error 1 make[1]: [all-recursive] Error 1 make: [all] Error 2 emmake: error: 'make -j8' failed (returned 2)