umlaeute / Gem

Graphics Environment for Multimedia (official repository)
https://gem.iem.at
Other
102 stars 29 forks source link

static build misses symbols when built with Emscripten #267

Open claudeha opened 3 years ago

claudeha commented 3 years ago

With Gem (not my older patched version, rather current upstream) built with Emscripten like this:

export CFLAGS="-s LEGACY_GL_EMULATION=1"
export CXXFLAGS="-s LEGACY_GL_EMULATION=1"
export LDFLAGS="-s LEGACY_GL_EMULATION=1"
export GL_CFLAGS="-s LEGACY_GL_EMULATION=1"
export GL_LIBS="-s LEGACY_GL_EMULATION=1"
export GLU_CFLAGS="-I${HOME}/9726/glu/include"
export GLU_LIBS="-L${HOME}/9726/glu/.libs -lGLU"
emconfigure ./configure --with-pd=${HOME}/code/github.com/claudeha/libpd/pure-data --disable-multicontext --enable-static --disable-shared 
emmake make -k

there seem to be symbols missing from the libGem.a, which breaks the final link:

~/code/github.com/claudeha/libpd/samples/emscripten/gemtest$ emmake make
make: make
emcc -I../../..//pure-data/src -I../../..//libpd_wrapper -O3 -o gemtest.html gemtest.c \
-s USE_SDL=2 \
-s LEGACY_GL_EMULATION=1 \
-s ERROR_ON_UNDEFINED_SYMBOLS=0 \
--preload-file test.pd \
--preload-file Gem \
-L../../..//build/libs -lpd /home/code/github.com/umlaeute/Gem/src/Gem/.libs/libGem.a
warning: undefined symbol: _Z10initGemWinv (referenced by top-level compiled C/C++ code)
warning: undefined symbol: _Z16destroyGemWindowR10WindowInfo (referenced by top-level compiled C/C++ code)
warning: undefined symbol: _Z17gemWinMakeCurrentR10WindowInfo (referenced by top-level compiled C/C++ code)
warning: undefined symbol: _Z17gemWinSwapBuffersR10WindowInfo (referenced by top-level compiled C/C++ code)
warning: undefined symbol: _ZN3gem3RTE3RTE21getRuntimeEnvironmentEv (referenced by top-level compiled C/C++ code)
warning: undefined symbol: _ZN3gem5utils2gl13glReportErrorEb (referenced by top-level compiled C/C++ code)
warning: undefined symbol: _ZN3gem5utils2gl9gluLookAtEddddddddd (referenced by top-level compiled C/C++ code)
warning: undefined symbol: _ZN3gem7Version12versionCheckEii (referenced by top-level compiled C/C++ code)
warning: undefined symbol: _ZN3gem7Version13versionStringEv (referenced by top-level compiled C/C++ code)
warning: undefined symbol: _ZN3gem7plugins4initEv (referenced by top-level compiled C/C++ code)
warning: undefined symbol: _ZN7GemSIMDC1Ev (referenced by top-level compiled C/C++ code)
warning: undefined symbol: _ZN7GemSIMDD1Ev (referenced by top-level compiled C/C++ code)
warning: undefined symbol: glColorMaterial (referenced by top-level compiled C/C++ code)
warning: undefined symbol: glLightModeli (referenced by top-level compiled C/C++ code)

and indeed the generated HTML+JS+WASM fails at runtime after printing GEM: Graphics Environment for Multimedia:

missing function: _ZN3gem7Version13versionStringEv
claudeha commented 3 years ago

Never mind, I just needed to link all the other .a files found in other directories. Would be nice if there was a single .a result combining all of them though!

claude@latte:~/code/github.com/claudeha/libpd/samples/emscripten/gemtest$ make
emcc -I../../..//pure-data/src -I../../..//libpd_wrapper -O3 -o gemtest.html gemtest.c \
-s USE_SDL=2 \
-s LEGACY_GL_EMULATION=1 \
-s ERROR_ON_UNDEFINED_SYMBOLS=0 \
--preload-file test.pd \
--preload-file Gem \
-L../../..//build/libs -lpd ../../../../Gem//src/Pixes/.libs/libPixes.a ../../../../Gem//src/Gem/.libs/libGem.a ../../../../Gem//src/Nongeos/.libs/libNongeos.a ../../../../Gem//src/Controls/.libs/libControls.a ../../../../Gem//src/Particles/.libs/libParticles.a ../../../../Gem//src/Particles/.libs/libPAPI.a ../../../../Gem//src/openGL/.libs/libopenGL.a ../../../../Gem//src/Manips/.libs/libManips.a ../../../../Gem//src/Geos/.libs/libGeos.a ../../../../Gem//src/plugins/.libs/libplugins.a ../../../../Gem//src/Base/.libs/libBase.a ../../../../Gem//src/Utils/.libs/libUtils.a ../../../../Gem//src/RTE/.libs/libRTE.a ../../../../glu//.libs/libGLU.a
warning: undefined symbol: glColorMaterial (referenced by top-level compiled C/C++ code)
warning: undefined symbol: glLightModeli (referenced by top-level compiled C/C++ code)
warning: metadce: missing declaration for emcc$export$dynCall_vi
claude@latte:~/code/github.com/claudeha/libpd/samples/emscripten/gemtest$ 
claudeha commented 3 years ago

Oh, it needs more -Wl,--whole-archive to actually include the code that defines the Pd objects in static constructors otherwise it isn't linked at all, and then the list of missing gl symbols is a mile long. Also need not to link libPAPI.a as it is already included in libParticles.a.

umlaeute commented 3 years ago

i cannot test right now, but PRs are always welcome ;-)