Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasm-ld: error: duplicate symbol #16

Open
jozefchutka opened this issue Oct 4, 2023 · 8 comments
Open

wasm-ld: error: duplicate symbol #16

jozefchutka opened this issue Oct 4, 2023 · 8 comments

Comments

@jozefchutka
Copy link

jozefchutka commented Oct 4, 2023

I am trying to compile piper with emscripten and so have it running in browser. I have come quite far including compiling onnxruntime, espeak-ng now I am stuck on some final steps with piper_phonemize build:

piper_phonemize is being built as a part of piper build process which I start with:

emmake make clean
emmake cmake -Bbuild -DCMAKE_INSTALL_PREFIX=install -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN_FILE -DBUILD_TESTING=OFF -G "Unix Makefiles"
emmake cmake --build build --config Release

I was able to fix a few issues during the build, however I can not figure out how to resolve duplicate symbol errors from wasm-ld.

[ 83%] Linking CXX executable piper_phonemize
em++: warning: ignoring unsupported linker flag: `-rpath` [-Wlinkflags]
em++: warning: ignoring unsupported linker flag: `-rpath` [-Wlinkflags]
wasm-ld: error: duplicate symbol: piper::phonemes_to_ids(std::__2::vector<char32_t, std::__2::allocator<char32_t>> const&, piper::PhonemeIdConfig&, std::__2::vector<long long, std::__2::allocator<long long>>&, std::__2::map<char32_t, unsigned long, std::__2::less<char32_t>, std::__2::allocator<std::__2::pair<char32_t const, unsigned long>>>&)
>>> defined in CMakeFiles/piper_phonemize_exe.dir/src/phoneme_ids.cpp.o
>>> defined in libpiper_phonemize.so.1.2.0
em++: error: '/piper-wasm/modules/emsdk/upstream/bin/wasm-ld -o piper_phonemize.wasm CMakeFiles/piper_phonemize_exe.dir/src/main.cpp.o CMakeFiles/piper_phonemize_exe.dir/src/phoneme_ids.cpp.o -L/piper-wasm/modules/piper/build/p/src/piper_phonemize_external-build/ei/lib -L/piper-wasm/modules/piper/build/p/src/piper_phonemize_external/lib/onnxruntime-linux-aarch64-1.14.1/lib libpiper_phonemize.so.1.2.0 /piper-wasm/modules/piper/build/p/src/piper_phonemize_external-build/ei/lib/libespeak-ng.so /piper-wasm/modules/piper/build/p/src/piper_phonemize_external/lib/onnxruntime-linux-aarch64-1.14.1/lib/libonnxruntime.so -L/piper-wasm/modules/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten -lGL -lal -lhtml5 -lstubs-debug -lnoexit -lc-debug -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-debug-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr /tmp/tmp4umjzg4dlibemscripten_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-if-defined=fflush --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_get_current --export=emscripten_stack_init --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 --stack-first --table-base=1' failed (returned 1)
gmake[5]: *** [CMakeFiles/piper_phonemize_exe.dir/build.make:119: piper_phonemize] Error 1
gmake[4]: *** [CMakeFiles/Makefile2:100: CMakeFiles/piper_phonemize_exe.dir/all] Error 2
gmake[3]: *** [Makefile:149: all] Error 2
gmake[2]: *** [CMakeFiles/piper_phonemize_external.dir/build.make:93: p/src/piper_phonemize_external-stamp/piper_phonemize_external-install] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:130: CMakeFiles/piper_phonemize_external.dir/all] Error 2
gmake: *** [Makefile:160: all] Error 2
emmake: error: 'cmake --build build --config Release' failed (returned 2)

any help will be much appreciated

@synesthesiam
Copy link
Contributor

Is it compiling both the library and exe into one package? Only the library would be needed.

@jozefchutka
Copy link
Author

jozefchutka commented Oct 5, 2023

Thanks for the tip. I managed to build working piper wasm with some code modifications and extra flags

/piper-wasm/modules/emsdk/upstream/emscripten/em++  -Wall -Wextra -Wl,-rpath,'$ORIGIN' -Wall -Wextra -Wl,-rpath,'$ORIGIN' @CMakeFiles/piper.dir/objects1.rsp -o piper.js @CMakeFiles/piper.dir/linklibs.rsp -lworkerfs.js -O3 -s INVOKE_RUN=0 -s MODULARIZE=1 -s EXPORT_NAME="createPiper" -s EXPORTED_FUNCTIONS="[_main]" -s EXPORTED_RUNTIME_METHODS="[callMain, FS, WORKERFS]" -s WASM_BIGINT=1 -s INITIAL_MEMORY=64mb -s ALLOW_MEMORY_GROWTH=1 -s MAXIMUM_MEMORY=4gb -s ENVIRONMENT=worker -s STACK_SIZE=5MB -s DEFAULT_PTHREAD_STACK_SIZE=2MB --preload-file  p/src/piper_phonemize_external-build/ei/share/espeak-ng-data@/espeak-ng-data

There are still some manual steps involved where I comment out piper_phonemize_exe from Makefile, customize emscripten so it compiles espeak-ng etc.

Anyway, you can check out demo here. Real-time factor in wasm is ~0.5 on my M2 vs. 0.04 using native build - so still room for improvements.

If you are interested to incorporate these changes into piper so emscripten build is smooth, please contact me, else you can close this issue.

Piper is great!

@eschmidbauer
Copy link

Thanks for sharing this, the demo is cool but it loads the model each time it runs inference. I suspect that is cuz it's calling the main() func in piper each time. I'm trying to get piper to load into browser and run inference as needed. I've had some success by loading the onnx model with onnxruntime-web, but the im unable to compute the inputIds (the phoneme_ids) required for the inference to run. I was thinking it would be cool to export piper-phonemize to wasm just to output the inputdata for the model. But im unable to build this piper_phonemize wasm. Any pointers would be appreciated, thanks!
image

@jozefchutka
Copy link
Author

any particular build step that fails?

@eschmidbauer
Copy link

image
building on an m2

@jozefchutka
Copy link
Author

On M2 (arm) I had to build onnxruntime using amd64 platform

git clone --depth 1 --branch v1.14.1 https://github.com/microsoft/onnxruntime.git modules/onnxruntime
docker run -it -v $(pwd)/modules/onnxruntime:/onnxruntime -w /onnxruntime --platform linux/amd64 debian:12.1

inside docker

uname -m # must say x86_64 !

@torphix
Copy link

torphix commented Nov 1, 2023

Hi @jozefchutka
Great work with the WASM build.
I was working on the port myself, but since you have done it already would you be open to sharing a link to the source code?
If not I understand

Thanks!

@jozefchutka
Copy link
Author

Hi @torphix

Follow https://github.com/wide-video/piper for changes in sources and https://github.com/wide-video/piper-wasm for build steps.

I was not able to automate the build steps and there are a lot of manual changes involved.

If you manage to improve the process please make a PR into https://github.com/wide-video/piper-wasm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants