emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.62k stars 3.28k forks source link

Linker errors after switching to new Emscripten 2.0.25 #14622

Open Honya2000 opened 3 years ago

Honya2000 commented 3 years ago

Hello,

Today I updated emsdk hoping it has fixed for emscripten fetch API undefined symbols... But unfortunately got additional problems:

The linker reports duplicated symbols, and I have no idea how to solve this:

wasm-ld: error: duplicate symbol: emscripten_GetProcAddress

defined in D:\Projects\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libGL-mt.a(gl.o) defined in D:\Projects\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libGL-mt-webgl2.a(gl.o)

wasm-ld: error: duplicate symbol: emscripten_webgl_get_proc_address

defined in D:\Projects\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libGL-mt.a(gl.o) defined in D:\Projects\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libGL-mt-webgl2.a(gl.o)

wasm-ld: error: duplicate symbol: _webgl1_match_ext_proc_address_without_suffix

defined in D:\Projects\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libGL-mt.a(webgl1.o) defined in D:\Projects\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libGL-mt-webgl2.a(webgl1.o)

wasm-ld: error: duplicate symbol: emscripten_webgl1_get_proc_address

defined in D:\Projects\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libGL-mt.a(webgl1.o) defined in D:\Projects\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libGL-mt-webgl2.a(webgl1.o)

wasm-ld: error: duplicate symbol: eglGetProcAddress

defined in D:\Projects\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libGL-mt.a(libprocaddr.o) defined in D:\Projects\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libGL-mt-webgl2.a(libprocaddr.o)

wasm-ld: error: duplicate symbol: glfwGetProcAddress

defined in D:\Projects\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libGL-mt.a(libprocaddr.o) defined in D:\Projects\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libGL-mt-webgl2.a(libprocaddr.o)

The point is I have no idea why it uses libGL-mt.a at all, because I specify -s MIN_WEBGL_VERSION=2 and -s MAX_WEBGL_VERSION=2 during linking.

P.S. Previously I used emsdk 2.0.23 and it didn't have problems with duplicates...

Honya2000 commented 3 years ago

This is part of linker command string:

D:\Projects\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libGL-mt.a -LD:\Projects\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten D:\Projects\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libSDL2-mt.a D:\Projects\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\crtbegin.o --whole-archive -lfetch-mt -lGL-mt-webgl2 -lembind --no-whole-archive -lal -lhtml5 -lc-mt -lcompiler_rt-mt -lc++-mt-noexcept -lc++abi-mt-noexcept -ldlmalloc-mt -lc_rt_wasm -lsockets-mt -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --allow-undefined --import-memory --shared-memory --strip-debug --export main --export stackSave --export stackRestore --export stackAlloc --export wasm_call_ctors --export errno_location --export emscripten_pthread_data_constructor --export __pthread_tsd_run_dtors --export _emscripten_call_on_thread --export _emscripten_do_dispatch_to_thread --export _emscripten_main_thread_futex --export _emscripten_thread_init --export emscripten_current_thread_process_queued_calls --export _emscripten_allow_main_runtime_queued_calls --export emscripten_futex_wake --export emscripten_get_global_libc --export emscripten_main_browser_thread_id --export emscripten_main_thread_process_queued_calls --export emscripten_register_main_browser_thread_id --export emscripten_run_in_main_runtime_thread_js --export emscripten_stack_set_limits --export emscripten_sync_run_in_main_thread_2 --export emscripten_sync_run_in_main_thread_4 --export emscripten_tls_init --export pthread_self --export memalign --export malloc --export free --export memcpy --export saveSetjmp --export setThrew --export-if-defined=start_em_asm --export-if-defined=__stop_em_asm --export-table -z stack-size=5242880 --initial-memory=16777216 --no-entry --max-memory=2147483648 --global-base=1024' failed (returned 1) ninja: build stopped: subcommand failed.

As you see it uses explicit lib: libGL-mt.a and uses command -lGL-mt-webgl2.

I do not specify this libs in my CMake files. It is somehow generated automatically by emscripten tools...

Honya2000 commented 3 years ago

I fixed this by providing linking flag -s USE_WEBGL2=1. Strange this was not required in previous emsdk.

kripken commented 3 years ago

That is very strange, yes...

If you have a little time, bisecting to find out where this changed would be very interesting:

https://emscripten.org/docs/contributing/developers_guide.html#bisecting