Emscripten link errors

I am trying to link the WebAssembly version of FMOD with a C/C++ shared object that will be used within the GameMaker Engine to provide an extension interface for FMOD, and I am getting link errors when getting to the link step.

The errors I am getting are

wasm-ld: error: ../../fmodstudioapi20213html5/api/core/lib/upstream/w32/fmod_reduced_wasm.a(fmod.o): relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `FMOD::gGlobal`; recompile with -fPIC
wasm-ld: error: ../../fmodstudioapi20213html5/api/core/lib/upstream/w32/fmod_reduced_wasm.a(fmod.o): relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `FMOD::gGlobal`; recompile with -fPIC
wasm-ld: error: ../../fmodstudioapi20213html5/api/core/lib/upstream/w32/fmod_reduced_wasm.a(fmod.o): relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `FMOD::gGlobal`; recompile with -fPIC
wasm-ld: error: ../../fmodstudioapi20213html5/api/core/lib/upstream/w32/fmod_reduced_wasm.a(fmod.o): relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `FMOD::gGlobal`; recompile with -fPIC
wasm-ld: error: ../../fmodstudioapi20213html5/api/core/lib/upstream/w32/fmod_reduced_wasm.a(fmod.o): relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `FMOD::gGlobal`; recompile with -fPIC
wasm-ld: error: ../../fmodstudioapi20213html5/api/core/lib/upstream/w32/fmod_reduced_wasm.a(fmod.o): relocation R_WASM_MEMORY_ADDR_SLEB cannot be used against symbol `.L.str`; recompile with -fPIC
wasm-ld: error: ../../fmodstudioapi20213html5/api/core/lib/upstream/w32/fmod_reduced_wasm.a(fmod.o): relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `FMOD::gGlobal`; recompile with -fPIC
wasm-ld: error: ../../fmodstudioapi20213html5/api/core/lib/upstream/w32/fmod_reduced_wasm.a(fmod.o): relocation R_WASM_MEMORY_ADDR_SLEB cannot be used against symbol `.L.str`; recompile with -fPIC
wasm-ld: error: ../../fmodstudioapi20213html5/api/core/lib/upstream/w32/fmod_reduced_wasm.a(fmod.o): relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `FMOD::gGlobal`; recompile with -fPIC
wasm-ld: error: ../../fmodstudioapi20213html5/api/core/lib/upstream/w32/fmod_reduced_wasm.a(fmod.o): relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `FMOD::gGlobal`; recompile with -fPIC
wasm-ld: error: ../../fmodstudioapi20213html5/api/core/lib/upstream/w32/fmod_reduced_wasm.a(fmod_channel_real.o): relocation R_WASM_MEMORY_ADDR_SLEB cannot be used against symbol `vtable for FMOD::ChannelReal`; recompile with -fPIC
wasm-ld: error: ../../fmodstudioapi20213html5/api/core/lib/upstream/w32/fmod_reduced_wasm.a(fmod_channel_software.o): relocation R_WASM_MEMORY_ADDR_SLEB cannot be used against symbol `vtable for FMOD::ChannelSoftware`; recompile with -fPIC
wasm-ld: error: ../../fmodstudioapi20213html5/api/core/lib/upstream/w32/fmod_reduced_wasm.a(fmod_channel_software.o): relocation R_WASM_MEMORY_ADDR_SLEB cannot be used against symbol `vtable for FMOD::DSPWaveTable`; recompile with -fPIC
wasm-ld: error: ../../fmodstudioapi20213html5/api/core/lib/upstream/w32/fmod_reduced_wasm.a(fmod_channel_software.o): relocation R_WASM_MEMORY_ADDR_SLEB cannot be used against symbol `vtable for FMOD::DSPSource`; recompile with -fPIC
wasm-ld: error: ../../fmodstudioapi20213html5/api/core/lib/upstream/w32/fmod_reduced_wasm.a(fmod_channel_software.o): relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `FMOD::ChannelReal::DEFAULT_MIN_FREQUENCY`; recompile with -fPIC
wasm-ld: error: ../../fmodstudioapi20213html5/api/core/lib/upstream/w32/fmod_reduced_wasm.a(fmod_channel_software.o): relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `FMOD::ChannelReal::DEFAULT_MAX_FREQUENCY`; recompile with -fPIC
wasm-ld: error: ../../fmodstudioapi20213html5/api/core/lib/upstream/w32/fmod_reduced_wasm.a(fmod_channel_software.o): relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `FMOD::ChannelReal::DEFAULT_MIN_FREQUENCY`; recompile with -fPIC
wasm-ld: error: ../../fmodstudioapi20213html5/api/core/lib/upstream/w32/fmod_reduced_wasm.a(fmod_channel_software.o): relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `FMOD::ChannelReal::DEFAULT_MIN_FREQUENCY`; recompile with -fPIC
wasm-ld: error: ../../fmodstudioapi20213html5/api/core/lib/upstream/w32/fmod_reduced_wasm.a(fmod_channel_software.o): relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol `FMOD::ChannelReal::DEFAULT_MAX_FREQUENCY`; recompile with -fPIC
wasm-ld: error: ../../fmodstudioapi20213html5/api/core/lib/upstream/w32/fmod_reduced_wasm.a(fmod_channel_software.o): relocation R_WASM_MEMORY_ADDR_SLEB cannot be used against symbol `vtable for FMOD::ChannelSoftware`; recompile with -fPIC
wasm-ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)

FMOD version is fmodstudioapi20213html5 and I am linking with the core/lib/upstream/w32 libraries as all of the others either do not suit my needs (I need to link to C++ to created a shared object library) we are not using fastcomp or JS .

I am using Emscrpten 3.1.9 for testing and compilation, but I have gotten the same results with 3.1.33

I am aware of Issues with compiling for HTML5 using emscripten but the advice in here is quite out of date (particularly in WebAssembly / Emscripten terms where things have moved on quite a bit)

I have tried various versions of clang and wasm-ld and I cannot duplicate the results that the above ticket indicates.

It would appear that the FMOD code should be compiled with -fPIC enabled to be linked using recent versions of Emscripten. Would it be possible to get a version of the library that has been compiled with -fPIC???

Russell

Hiya,

Sorry for the late reply - there’s some complexities with compiling the WASM version to a library that I need to coordinate with the development team about, but I should get back to you on this soon.

Sorry again for the late reply,

I’m unable to reproduce the issue on my end. I’ve able to successfully compile a shared object library that uses FMOD with Emscripten 3.1.33, using the following command:

emcc -c mylibrary.c -o mylibrary.o

And compile an application that uses the shared object library using this command:

emcc -O3 consume.c fmod_reduced_wasm.a fmod_reduced_bindings.a -o index.html mylibrary.o --preload-file assets -s EXTRA_EXPORTED_RUNTIME_METHODS=[ccall,cwrap,setValue,getValue] -s INITIAL_MEMORY=67108864 -s ASYNCIFY

It’s worth noting that it appears that the FMOD library needs to be linked at the application compilation stage, and not at the library compilation stage. Are you trying to link FMOD directly to your shared library, or have you tried linking it into your application?

We have to compile FMOD into the shared object library and not into the executable as the GameMaker executable is precompiled and only shared objects can be used as extensions.

We cannot compile FMOD into each version of GameMaker as then every GM game would have to agree to the FMOD agreement and then they would be subject to licensing (technically even if they did or did not use FMOD within the code)

Russell

Unfortunately, under the standard EULA we don’t allow repackaging/redistribution of fixed versions of the FMOD Engine. If you would like to proceed with this line of inquiry, I would recommend getting in touch with sales@fmod.com about acquiring the appropriate license.