4

I'm trying to build a C++ SDL2 project with Emscripten with the script below but I got the undefined symbol error. Here's the build script:

em++ src/* \
  -I include \
  -s USE_SDL=2 \
  -s USE_SDL_IMAGE=2 \
  -s SDL2_IMAGE_FORMATS='["png"]' \
  --preload-file res \
  -o web/project.html 

Here's the error:

error: undefined symbol: __invoke_$struct_SDL_Surface*_i32_i32_i32_i32_i32_i32_i32_i32 (referenced by top-level compiled C/C++ code)
warning: Link with `-s LLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
warning: ___invoke_$struct_SDL_Surface*_i32_i32_i32_i32_i32_i32_i32_i32 may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_$struct_png_info_def*_$struct_png_struct_def* (referenced by top-level compiled C/C++ code)
warning: ___invoke_$struct_png_info_def*_$struct_png_struct_def* may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_$struct_png_struct_def*_i8*_i8*_void($struct_png_struct_def*_i8*)*_void($struct_png_struct_def*_i8*)* (referenced by top-level compiled C/C++ code)
warning: ___invoke_$struct_png_struct_def*_i8*_i8*_void($struct_png_struct_def*_i8*)*_void($struct_png_struct_def*_i8*)* may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_[1x$struct___jmp_buf_tag]*_$struct_png_struct_def*_void($struct___jmp_buf_tag*_i32)*_i32 (referenced by top-level compiled C/C++ code)
warning: ___invoke_[1x$struct___jmp_buf_tag]*_$struct_png_struct_def*_void($struct___jmp_buf_tag*_i32)*_i32 may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_i32_$struct_SDL_PixelFormat*_i8_i8_i8 (referenced by top-level compiled C/C++ code)
warning: ___invoke_i32_$struct_SDL_PixelFormat*_i8_i8_i8 may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_i32_$struct_SDL_Surface*_i32_i32 (referenced by top-level compiled C/C++ code)
warning: ___invoke_i32_$struct_SDL_Surface*_i32_i32 may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_i32_$struct_png_struct_def*_$struct_png_info_def*_$struct_png_color_struct**_i32* (referenced by top-level compiled C/C++ code)
warning: ___invoke_i32_$struct_png_struct_def*_$struct_png_info_def*_$struct_png_color_struct**_i32* may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_i32_$struct_png_struct_def*_$struct_png_info_def*_i32 (referenced by top-level compiled C/C++ code)
warning: ___invoke_i32_$struct_png_struct_def*_$struct_png_info_def*_i32 may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_i32_$struct_png_struct_def*_$struct_png_info_def*_i32*_i32*_i32*_i32*_i32*_i32*_i32* (referenced by top-level compiled C/C++ code)
warning: ___invoke_i32_$struct_png_struct_def*_$struct_png_info_def*_i32*_i32*_i32*_i32*_i32*_i32*_i32* may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_i32_$struct_png_struct_def*_$struct_png_info_def*_i8**_i32*_$struct_png_color_16_struct** (referenced by top-level compiled C/C++ code)
warning: ___invoke_i32_$struct_png_struct_def*_$struct_png_info_def*_i8**_i32*_$struct_png_color_16_struct** may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_i32_$struct_png_struct_def*_i8* (referenced by top-level compiled C/C++ code)
warning: ___invoke_i32_$struct_png_struct_def*_i8* may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_i32_i32 (referenced by top-level compiled C/C++ code)
warning: ___invoke_i32_i32 may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_i32_i8*____ (referenced by top-level compiled C/C++ code)
warning: ___invoke_i32_i8*____ may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_i64_$struct_SDL_RWops* (referenced by top-level compiled C/C++ code)
warning: ___invoke_i64_$struct_SDL_RWops* may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_i64_$struct_SDL_RWops*_i64_i32 (referenced by top-level compiled C/C++ code)
warning: ___invoke_i64_$struct_SDL_RWops*_i64_i32 may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_i8* (referenced by top-level compiled C/C++ code)
warning: ___invoke_i8* may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_i8*_$struct_png_struct_def*_i32 (referenced by top-level compiled C/C++ code)
warning: ___invoke_i8*_$struct_png_struct_def*_i32 may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_i8*_i32 (referenced by top-level compiled C/C++ code)
warning: ___invoke_i8*_i32 may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_i8_$struct_png_struct_def*_$struct_png_info_def* (referenced by top-level compiled C/C++ code)
warning: ___invoke_i8_$struct_png_struct_def*_$struct_png_info_def* may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_void_$struct_SDL_Surface* (referenced by top-level compiled C/C++ code)
warning: ___invoke_void_$struct_SDL_Surface* may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_void_$struct_png_struct_def* (referenced by top-level compiled C/C++ code)
warning: ___invoke_void_$struct_png_struct_def* may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_void_$struct_png_struct_def**_$struct_png_info_def**_$struct_png_info_def** (referenced by top-level compiled C/C++ code)
warning: ___invoke_void_$struct_png_struct_def**_$struct_png_info_def**_$struct_png_info_def** may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_void_$struct_png_struct_def*_$struct_png_info_def* (referenced by top-level compiled C/C++ code)
warning: ___invoke_void_$struct_png_struct_def*_$struct_png_info_def* may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_void_$struct_png_struct_def*_i8* (referenced by top-level compiled C/C++ code)
warning: ___invoke_void_$struct_png_struct_def*_i8* may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_void_$struct_png_struct_def*_i8** (referenced by top-level compiled C/C++ code)
warning: ___invoke_void_$struct_png_struct_def*_i8** may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_void_$struct_png_struct_def*_i8*_i8*($struct_png_struct_def*_i32)*_void($struct_png_struct_def*_i8*)* (referenced by top-level compiled C/C++ code)
warning: ___invoke_void_$struct_png_struct_def*_i8*_i8*($struct_png_struct_def*_i32)*_void($struct_png_struct_def*_i8*)* may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_void_$struct_png_struct_def*_i8*_void($struct_png_struct_def*_i8*)*_void($struct_png_struct_def*_i8*)* (referenced by top-level compiled C/C++ code)
warning: ___invoke_void_$struct_png_struct_def*_i8*_void($struct_png_struct_def*_i8*)*_void($struct_png_struct_def*_i8*)* may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_void_$struct_png_struct_def*_i8*_void($struct_png_struct_def*_i8*_i32)* (referenced by top-level compiled C/C++ code)
warning: ___invoke_void_$struct_png_struct_def*_i8*_void($struct_png_struct_def*_i8*_i32)* may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: __invoke_void_i8* (referenced by top-level compiled C/C++ code)
warning: ___invoke_void_i8* may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: emscripten_longjmp_jmpbuf (referenced by top-level compiled C/C++ code)
warning: _emscripten_longjmp_jmpbuf may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
em++: error: '/usr/bin/node /usr/share/emscripten/src/compiler.js /tmp/tmpxxp75z4u.txt' failed (1)

If I understand the documentation correctly, SDL2 and SDL2_image are in emscripten ports, which means that I simply need to add the flags -s USE_SDL=2 -s USE_SDL_IMAGE=2 to build the project with those two libraries using em++, without specifying the include dir and link dirs explicitly. However, this doesn't seem to work.

(My OS is Debian testing. To build this project natively, I use CMake and I have installed the SDL2 packages with apt.)

kwsp
  • 1,184
  • 7
  • 26
  • 2
    Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Öö Tiib Jun 06 '21 at 11:32
  • @ÖöTiib No. `em++` should be using SDL2 and SDL2_image from emscripten-ports, which, in the [documentation](https://emscripten.org/docs/compiling/Building-Projects.html?highlight=sdl2#emscripten-ports), should work by simply adding the flags `-s USE_SDL=2 -s USE_SDL_IMAGE=2`. – kwsp Jun 06 '21 at 11:39
  • Seems to document emcc not em++. So have you ever got any concrete examples / test code (links are in that documentation) to work? Or what gives you reason to think that it is different from all the usual. – Öö Tiib Jun 06 '21 at 11:51
  • Right, I don't see concrete examples for `em++`, only `emcc`. I've been able to compile the trivial C++ examples with `em++`, just not with SDL2. – kwsp Jun 06 '21 at 14:15
  • Hi, have you installed SDL and its dependencies on your system? – kalwalt Jun 13 '21 at 21:55
  • Have you tried building it with cmake (emcmake cmake, emmake make)? Your build script looks fine to me. @kalwalt It shouldn't matter if it's installed on the host system, as it's not linking there anyway. – cajomar Jun 14 '21 at 23:38
  • I have used SDL in small projects under Ubuntu, maybe with Debian is required to install some other packages. The errors are related to png maybe is required the png package? If you don't find a solution maybe you can file an issue on the emscripten issue tracker. – kalwalt Jun 26 '21 at 21:23

0 Answers0