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
.)