Repository navigation
wasm-ld: error: dist/lib/libavformat.a: archive has no index; run ranlib to add one #9705
Copy link
Copy link
Closed
Labels
Description
Hi,
I'm getting these errors while compiling ffmpeg with emcc
wasm-ld: error: dist/lib/libavformat.a: archive has no index; run ranlib to add one
wasm-ld: error: dist/lib/libavcodec.a: archive has no index; run ranlib to add one
wasm-ld: error: dist/lib/libavutil.a: archive has no index; run ranlib to add one
wasm-ld: error: dist/lib/libswscale.a: archive has no index; run ranlib to add one
shared:ERROR: '/opt/h265player/emsdk/upstream/bin/wasm-ld -o /tmp/emscripten_temp_jCijDj/libffmpeg.wasm --allow-undefined --lto-O0 /tmp/emscripten_temp_jCijDj/decoder_0.o dist/lib/libavformat.a dist/lib/libavcodec.a dist/lib/libavutil.a -L/opt/h265player/emsdk/upstream/emscripten/system/local/lib dist/lib/libswscale.a -L/opt/h265player/emsdk/upstream/emscripten/system/lib -L/root/.emscripten_cache/wasm-obj /root/.emscripten_cache/wasm-obj/libc.a /root/.emscripten_cache/wasm-obj/libcompiler_rt.a /root/.emscripten_cache/wasm-obj/libc-wasm.a /root/.emscripten_cache/wasm-obj/libdlmalloc.a /root/.emscripten_cache/wasm-obj/libpthread_stub.a /root/.emscripten_cache/wasm-obj/libc_rt_wasm.a --import-memory --import-table -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --export __wasm_call_ctors --export __data_end --export initDecoder --export uninitDecoder --export openDecoder --export closeDecoder --export sendData --export decodeOnePacket --export seekTo --export main --export malloc --export free --export setThrew --export __errno_location --export _get_tzname --export _get_daylight --export _get_timezone --export emscripten_builtin_memalign --export memalign --export emscripten_builtin_free --export _get_environ -z stack-size=5242880 --initial-memory=67108864 --no-entry --max-memory=67108864 --global-base=1024' failed (1)
Finished Build
(I see this error referenced in #9329 but i already set [--cc="emcc" --ar="emar"].)
The below is the build script
- build_decoder.sh
echo "Beginning Build:"
rm -r dist
mkdir -p dist
cd ../ffmpeg
make clean
emconfigure ./configure --cc="emcc" --cxx="em++" --ar="emar" --prefix=$(pwd)/../WasmVideoPlayer/dist --enable-cross-compile --target-os=none \
--arch=x86_32 --cpu=generic --enable-gpl --enable-version3 --disable-avdevice --disable-swresample --disable-postproc --disable-avfilter \
--disable-programs --disable-logging --disable-everything --enable-avformat --enable-decoder=hevc --enable-decoder=h264 --enable-decoder=aac \
--disable-ffplay --disable-ffprobe --disable-ffserver --disable-asm --disable-doc --disable-devices --disable-network --disable-hwaccels \
--disable-parsers --disable-bsfs --disable-debug --enable-protocol=file --enable-demuxer=mov --disable-indevs --disable-outdevs
make
make install
cd ../WasmVideoPlayer
./build_decoder_wasm.sh
2)build_decoder_wasm.sh
rm -rf libffmpeg.wasm libffmpeg.js
export TOTAL_MEMORY=67108864
export EXPORTED_FUNCTIONS="[ \
'_initDecoder', \
'_uninitDecoder', \
'_openDecoder', \
'_closeDecoder', \
'_sendData', \
'_decodeOnePacket', \
'_seekTo', \
'_main'
]"
echo "Running Emscripten..."
emcc decoder.c dist/lib/libavformat.a dist/lib/libavcodec.a dist/lib/libavutil.a dist/lib/libswscale.a \
-O3 \
-I "dist/include" \
-s WASM=1 \
-s TOTAL_MEMORY=${TOTAL_MEMORY} \
-s EXPORTED_FUNCTIONS="${EXPORTED_FUNCTIONS}" \
-s EXTRA_EXPORTED_RUNTIME_METHODS="['addFunction']" \
-s RESERVED_FUNCTION_POINTERS=14 \
-s FORCE_FILESYSTEM=1 \
-v \
-o libffmpeg.js
echo "Finished Build"
Reactions are currently unavailable
Activity
sbc100 commentedon Oct 25, 2019
I would look at the commands used to build the libraries. According the wasm-ld they don't have indexes. How is
dist/lib/libavcodec.abeing built? Can you post the command?bvibber commentedon Oct 25, 2019
I had a similar error with a library that used the 'strip' command in it's build process to remove debugging symbols from the .a artifact. On Linux this seemed to get confused with the new backend and damaged the files; replacing strip with a no-op worked around it. Might be something to check for.
sbc100 commentedon Oct 25, 2019
Interesting. Presumably this is because the native
stripdoesn't know anything about wasm object format. I'm surprised it clobbered the existing index though. Another solution there is to replacestripwillllvm-stripwhich does know about those symbols.kripken commentedon Oct 25, 2019
I'm curious what version version this was on, and which backend - if this is a regression in the new backend that would be worrying.
sbc100 commentedon Oct 25, 2019
I would imagine the same thing would happen with fastcomp, since
stripalso won't understand bitcode files, but perhaps fastcomp linking doesn't require a index in the way that wasm-ld does? If thats the case then we have become stricter yes. I'll will check. If if that is the case I'm not sure that really counts a regression but we should document it for sure.Document different handling of archive files with the wasm backend
Document different handling of archive files with the wasm backend (#…
bvibber commentedon Oct 25, 2019
Here's a gist with a small library build that triggers the different behavior between fastcomp (where it builds) and upstream (where it gives you the 'no index' error):
https://gist.github.com/brion/ef605cb6b71a81c763c59ed15efd9a78
I definitely recommend checking the ffmpeg build process for it running
stripor other such modifications on the binaries, especially if it's being compiled in release mode that's a common thing to do. It may be easy to override the executable, or you may have to hack up the build or play tricks with the PATH. ;)yyqangular1 commentedon Oct 28, 2019
very sorry, i'm later :(
I use this command to build ffmpeg:
Compiled to generate the following files:
No error at this step, but when i build my project...(Below is my project directory)
the build commond is this:
I got the wasm-ld: error: dist/lib/libavformat.a: archive has no index; run ranlib to add one
sbc100 commentedon Oct 28, 2019
Can you remove the libavformat.a library and the rebuilt it in order to see exactly how it is being build?
e.g.
kripken commentedon Oct 28, 2019
@sbc100
Looks like this may be a common problem given the simple reproducer @Brion provided. Perhaps the error
wasm-ld: error: ./liba.a: archive has no index; run ranlib to add onecould say a little more, like(avoid using the system "strip" command as it may remove the wasm index)?Alternatively, could
wasm-ldcreate the index on demand perhaps?sbc100 commentedon Oct 28, 2019
I don't think it makes sense to build such magic into wasm-ld, but we can build more magic into emscripten if we like.
How about this:
?
kripken commentedon Oct 28, 2019
@sbc100 that sounds good!
yyqangular1 commentedon Oct 29, 2019
Of course,when i rebuild it, the compilation process is as follows:(sorry,the info is too long:()
Some warning messages during the compilation process.
Is there any problem here?
sbc100 commentedon Oct 30, 2019
I built this locally and did some debugging:
So it looks like ffmpeg calls ranlib directly. If you want this to work you also need to specify
--ranlib=emranlibon the configure command line.You will also need to install 1.39.1 in order to get the fix for ranlib itself: #9714
arkonchen commentedon Oct 31, 2019
you can add --ranlib="emranlib" to build success
yyqangular1 commentedon Oct 31, 2019
Yes, after specifying this paramter [--ranlib="emranlib"], build successfully.
Thx :) I will close this issue later.
Automatically run ranlib on archives with missing index
Automatically run ranlib on archives with missing index
Automatically run ranlib on archives with missing index
Automatically run ranlib on archives with missing index (#9758)
Document different handling of archive files with the wasm backend (e…
Automatically run ranlib on archives with missing index (emscripten-c…