尝试使用 Emscripten 构建 C++ SDL2 项目时出现未定义符号

问题描述 投票:0回答:1

我正在尝试使用 Emscripten 构建一个 C++ SDL2 项目:

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 

...但是我收到了

undefined symbol
错误:

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)

如果我正确理解文档,SDL2和SDL2_image位于emscripten端口中,这意味着我只需添加标志

-s USE_SDL=2 -s USE_SDL_IMAGE=2
即可使用
em++
使用这两个库构建项目,而不需要指定包含目录和明确链接目录。然而,这似乎不起作用。

(我的操作系统是 Debian 测试。为了本地构建这个项目,我使用

CMake
并使用
apt
安装了 SDL2 软件包。)

c++ sdl-2 emscripten
1个回答
0
投票

添加

-lSDL2
手动为我修复了它。

© www.soinside.com 2019 - 2024. All rights reserved.