mosra / magnum

Lightweight and modular C++11 graphics middleware for games and data visualization
https://magnum.graphics/
Other
4.75k stars 439 forks source link

emscripten: Duplicate defined webgl symbols #575

Closed Squareys closed 11 months ago

Squareys commented 2 years ago

The FindGLES3.cmake links the GL library and for CMake >= 3.13 also adds -s USE_WEBGL2=1. Doing both leads to duplicate defined GL symbols, removing the INTERFACE_LINK_LIBRARIES property fixes the issue.

See also https://github.com/emscripten-core/emscripten/issues/14622.

@mosra Any preference on how this should be fixed? i.e. Remove the link library or the link option?

mosra commented 2 years ago

Wait, what? So you're saying -lGL -s USE_WEBGL2=1 causes ... what actually? I suspect the problem is somewhere else, this has always worked.

The -s USE_WEBGL2=1 flag is added for 3.13+, yes, but as the comment says, for versions before the same is done in FindMagnum.cmake, so what you're doing in that commit is not really fixing anything: https://github.com/mosra/magnum/blob/527ee0f45d3414f23cf6f16f75c5cd4cf4ac6664/modules/FindMagnum.cmake#L1035-L1051

The -lGL is there because it's required for the minimal Emscripten runtime -- see fa50929c78fd48441183cc8dcdc6d0044f7afe85. Reverting that means MINIMAL_RUNTIME gets broken again, so I don't think this is something I should be removing.

The referenced Emscripten issue is a year old and seems to point to something inside Emscripten's own CMake toolchain, which we don't use for various reasons, so I don't think that's related. What linker errors are you actually getting? Can you paste them here? Ideally, including the whole linker command line as shown by ninja -v.

Squareys commented 1 year ago

As you know we had some issues with our CMake toolchain setup, so this might resolve once we resolve them. I'll report back once we figured that out. Either way, emscripten figures out the -l flags itself, so -lGL should not be required, it's implicitly added via -sUSE_WEBGL2=1.

mosra commented 1 year ago

emscripten figures out the -l flags itself, so -lGL should not be required

Not the case for MINIMAL_RUNTIME, as I said above. There it needs to be explicit, and that's the whole reason for the flag to be present.

I'll wait until you report back, but I think the issue was something with the toolchain setup rather than the presence of -lGL being a problem.

mosra commented 1 year ago

Bump -- is any of this still relevant? As I said above, I don't think this has anything to do with Magnum or the toolchain, but rather seems to be some particularly nasty case of a broken setup :sweat_smile:

Cc: @pezcode

mosra commented 11 months ago

Did some more investigation. Not reproducible on Emscripten 3.1.44 in PlatformEmscriptenApplicationTest with -s MINIMAL_RUNTIME=2 -s USE_WEBGL2=1 -lGL. On the other omitting -lGL leads to undefined symbol: emscripten_webgl_init_context_attributes with MINIMAL_RUNTIME being used, so the flag is clearly needed.