gpt4 book ai didi

c - Emscripten SDL 编译失败

转载 作者:行者123 更新时间:2023-11-30 16:32:24 25 4
gpt4 key购买 nike

我是 emscripten 新手;几天前我下载了它只是为了尝试将游戏移植到 JS。

无论如何,经过一些步骤后,我现在遇到了这个问题(在 Ubuntu 16.04 STL 上)。通过遵循构建步骤 here ,首先,我设置了环境变量 source ./emsdk_env.sh然后我尝试使用 emconfigure ./configure 配置项目在项目目录中。在检查 emscripten 需要的工具时,出现此错误:

checking for SDL... no
configure: error: Package requirements (sdl2 >= 2.0.1) were not met:

No package 'sdl2' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables SDL_CFLAGS
and SDL_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
ERROR:root:Configure step failed with non-zero return code 1! Command line: ['./configure'] at ...

所以我尝试使用以下命令设置该变量: export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig/这实际上是sdl2.pc位于我的机器上,但没有帮助。

然后我设置了以下变量 emconfigure需要:

export SDL_PATH=/home/ustym/Documents/Projects/emsdk/emscripten/1.37.38/system/include/SDL/SDL.h
export SDL_LIBS=/home/ustym/Documents/Projects/emsdk/emscripten/1.37.38/system/include/SDL/SDL.h
export SDL_CFLAGS=/home/ustym/Documents/Projects/emsdk/emscripten/1.37.38/system/include/SDL/SDL.h
export SDLNET_LIBS=/home/ustym/Documents/Projects/emsdk/emscripten/1.37.38/system/include/SDL/SDL.h
export SDLNET_CFLAGS=/home/ustym/Documents/Projects/emsdk/emscripten/1.37.38/system/include/SDL/SDL.h
export SDLMIXER_LIBS=/home/ustym/Documents/Projects/emsdk/emscripten/1.37.38/system/include/SDL/SDL.h
export SDLMIXER_CFLAGS=/home/ustym/Documents/Projects/emsdk/emscripten/1.37.38/system/include/SDL/SDL.h

并重新启动emconfigure ./configure已经完成得很好。所以下一步是emmake make这给了我以下错误:

make  all-recursive
make[1]: Entering directory '/home/ustym/Documents/Projects/chocolate-doom-3.0.0'
Making all in textscreen
make[2]: Entering directory '/home/ustym/Documents/Projects/chocolate-doom-3.0.0/textscreen'
Making all in fonts
make[3]: Entering directory '/home/ustym/Documents/Projects/chocolate-doom-3.0.0/textscreen/fonts'
make[3]: Nothing to be done for 'all'.
make[3]: Leaving directory '/home/ustym/Documents/Projects/chocolate-doom-3.0.0/textscreen/fonts'
Making all in .
make[3]: Entering directory '/home/ustym/Documents/Projects/chocolate-doom-3.0.0/textscreen'
CC txt_conditional.o
Traceback (most recent call last):
File "/home/ustym/Documents/Projects/emsdk/emscripten/1.37.38/emcc", line 11, in <module>
python_selector.run(__file__)
File "/home/ustym/Documents/Projects/emsdk/emscripten/1.37.38/tools/python_selector.py", line 38, in run
sys.exit(run_by_import(filename, main) if on_allowed_version() else run_by_subprocess(filename))
File "/home/ustym/Documents/Projects/emsdk/emscripten/1.37.38/tools/python_selector.py", line 13, in run_by_import
return getattr(importlib.import_module(os.path.basename(filename)), main)()
File "/home/ustym/Documents/Projects/emsdk/emscripten/1.37.38/emcc.py", line 1345, in run
assert header.endswith(HEADER_ENDINGS), 'if you have one header input, we assume you want to precompile headers, and cannot have source files or other inputs as well: ' + str(headers) + ' : ' + header
AssertionError: if you have one header input, we assume you want to precompile headers, and cannot have source files or other inputs as well: ['/home/ustym/Documents/Projects/emsdk/emscripten/1.37.38/system/include/SDL/SDL.h', 'txt_conditional.c'] : txt_conditional.c
Makefile:447: recipe for target 'txt_conditional.o' failed
make[3]: *** [txt_conditional.o] Error 1
make[3]: Leaving directory '/home/ustym/Documents/Projects/chocolate-doom-3.0.0/textscreen'
Makefile:467: recipe for target 'all-recursive' failed
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory '/home/ustym/Documents/Projects/chocolate-doom-3.0.0/textscreen'
Makefile:585: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/ustym/Documents/Projects/chocolate-doom-3.0.0'
Makefile:438: recipe for target 'all' failed
make: *** [all] Error 2

我认为这意味着 SDL_PATH , SDL_LIBS , SDL_CFLAGS ...变量设置不正确。或者也许我只需要在 SDL 目录中预编译该 header 。

最后一件事:如果我跳过设置 SDL 变量和配置步骤并直接启动 emmake make ,编译进行得很顺利,但是,emcc命令给我 WARNING:root: .o is not valid LLVM bitcode对于所有生成的 .o文件。这实际上是有道理的。

所以我被困在这里了。有人可以告诉我如何正确设置PKG_CONFIG_PATH对于 emscripten 或者我是否真的需要在 SDL 目录中预编译这些 header ?谢谢!

最佳答案

首先,设置PKG_CONFIG_PATH,包括,甚至更糟糕的是,库目录(-I-L)来托管库对我来说,这看起来是个糟糕的主意:Emscripten 对象文件包含 LLVM 位码(而不是主机机器代码),它的 .so 文件 AFAIK 也包含位码。被转换为 JS 的是位代码,而不是主机机器代码。因此,您需要自己使用 Emscripten 构建程序的依赖项(并且很可能不应该将它们安装到主机系统)。幸运的是,有一些官方的 Emscripten 端口(请参阅 here )了解详细信息。

Emscripten 有自己的 SDL v1 实现(您可能尝试手动使用),但您的程序似乎需要 SDL2。好消息:您可能只需要在配置时将 -s USE_SDL=2 传递给 CFLAGSLDFLAGS (有关 SDL2 端口的信息,请参阅上面的链接的后面部分)。坏消息:某些内容可能无法完全移植。但我在某种程度上成功地使用了它。

当您在主机上进行 configured 并使用 emmake 进行 make 时,您可能在由 emconfigure 调整的其他参数中设置了编译器路径emmake 已通过 ./configure 烘焙到生成的 Makefile 中,不受 emconfigure 控制,因此托管 gcc/clang 刚刚生成的机器代码。

关于c - Emscripten SDL 编译失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50169110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com