emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.8k stars 3.31k forks source link

Emcc cannot find SDL2 libraries #22579

Closed jnt0rrente closed 1 month ago

jnt0rrente commented 1 month ago

Basically the title. I am trying to port a simple raytracer app to WASM using Emscripten, but build is failing during the compilation stage.

This is my full emcc call:

emcc -o raytracer.js raytracer.js.p/src_main.cpp.o raytracer.js.p/src_scene.cpp.o raytracer.js.p/src_gui_interface_utils.cpp.o raytracer.js.p/src_gui_interface.cpp.o raytracer.js.p/src_gui_gui_visitor.cpp.o raytracer.js.p/src_raytracer_camera.cpp.o raytracer.js.p/src_raytracer_color.cpp.o raytracer.js.p/src_raytracer_hittable.cpp.o raytracer.js.p/src_raytracer_material.cpp.o raytracer.js.p/src_raytracer_ray.cpp.o raytracer.js.p/src_raytracer_sphere3d.cpp.o raytracer.js.p/src_raytracer_vector3d.cpp.o raytracer.js.p/src_raytracer_world.cpp.o raytracer.js.p/src_utils_math_utils.cpp.o -sERROR_ON_UNDEFINED_SYMBOLS=1 --use-preload-plugins --use-port=sdl2 --use-port=sdl2_image:formats=bmp,png,xpm,jpg --use-preload-plugins --use-port=libpng --use-port=libjpeg -Wl,--start-group libimgui.a -pthread -lm -lSDL2 /usr/lib/libz.a /usr/lib/libstdc++.a -lpthread -ldl /usr/lib/libutil.a -lrt -lc -lSDL2_image -lSDL2 -lpng16 -ljxl -lhwy -lbrotlienc -lbrotlidec -lbrotlicommon -ljxl_cms -ltiff -ljbig -lzstd -llzma -ljpeg -lavif -lyuv -ldav1d -lrav1e -lgcc_s -lSvtAv1Enc -laom -lwebpdemux -lwebp -lsharpyuv -Wl,--end-group

First, I get many wasm-ld warnings, such as these:

wasm-ld: warning: /usr/lib/libz.a: archive member 'gzwrite.o' is neither Wasm object file nor LLVM bitcode wasm-ld: warning: /usr/lib/libstdc++.a: archive member 'compatibility.o' is neither Wasm object file nor LLVM bitcode

Then the errors that cause the linking to stop:

wasm-ld: error: unable to find library -lpng16 wasm-ld: error: unable to find library -ljxl wasm-ld: error: unable to find library -lhwy wasm-ld: error: unable to find library -lbrotlienc

I am building with Meson and I can provide my .build file, but i'm assuming that would be out of the scope for this repo. Any tips on where to start debugging this?

jnt0rrente commented 1 month ago

Just solved it. The problem was that I was specifying SDL2 and SDL2_image as explicit dependencies and that was conflicting with the required --use-port=sdl2 .

Leaving the issue up in case someone else runs into the same problem - delete it if you see it fit.