首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Emscripten SDL编译失败

Emscripten SDL编译失败
EN

Stack Overflow用户
提问于 2018-05-04 15:05:20
回答 1查看 417关注 0票数 0

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

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

代码语言:javascript
复制
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所需的以下变量:

代码语言:javascript
复制
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,它会给我以下错误:

代码语言:javascript
复制
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_PATHSDL_LIBSSDL_CFLAGS...变量设置不正确。或者我只需要在SDL目录中预编译头文件。

最后一件事:如果我跳过设置SDL变量和配置步骤,只启动emmake make,编译就会正常进行,但是emcc命令会为所有生成的.o文件提供WARNING:root: .o is not valid LLVM bitcode。这实际上是有道理的。

所以我被困在这里了。有人能告诉我如何为emscripten设置正确的PKG_CONFIG_PATH,或者我是否真的需要在SDL目录中预编译头文件?谢谢!

EN

回答 1

Stack Overflow用户

发布于 2018-05-08 01:54:00

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

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

当您在主机上使用configured并使用emmake时,您可能已经将编译器路径以及由emconfigure调整的其他参数和emmake已经烘焙到由./configure生成的Makefile中,而不是由emconfigure控制,因此主机gcc/clang只生成了机器码。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50169110

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档