【问题标题】:How to make emcc work?如何使 emcc 工作?
【发布时间】:2015-04-17 14:16:18
【问题描述】:

当我尝试使用 emcc 将 C 代码编译成 Javascript 时,我收到以下错误:

emcc tests/hello_world.c 
CRITICAL root: fastcomp in use, but LLVM has not been built with the JavaScript backend as a target, llc reports:
===========================================================================
LLVM (http://llvm.org/):
  LLVM version 3.5.1
  Optimized build with assertions.
  Built Feb 22 2015 (00:08:56).
  Default target: x86_64-apple-darwin13.4.0
  Host CPU: corei7-avx

  Registered Targets:
    x86    - 32-bit X86: Pentium-Pro and above
    x86-64 - 64-bit X86: EM64T and AMD64
===========================================================================
CRITICAL root: you can fall back to the older (pre-fastcomp) compiler core, although that is not recommended, see https://github.com/kripken/emscripten/wiki/LLVM-Backend
INFO     root: (Emscripten: Running sanity checks)
CRITICAL root: failing sanity checks due to previous fastcomp failure

如何解决这个问题?如何回退到 pre-fast-comp?

【问题讨论】:

    标签: llvm emscripten


    【解决方案1】:

    我在从源代码手动构建 Emscripten 时解决了同样的错误。

    Emscripten 使用自己的 LLVM 分支 - Fastcomp; 按照说明here 从源代码构建它。然后编辑~/.emscripten 使LLVM_ROOT 像这样

    LLVM_ROOT = os.path.expanduser('/home/yourpath/to/emscripten-fastcomp/build/Release/bin') # directory
    

    (甚至可以是/home/yourpath/to/emscripten-fastcomp/build/bin

    【讨论】:

    • 我更改了emsdk的父文件夹,不得不调整里面的路径:~/.emscripten
    【解决方案2】:

    这看起来像是配置错误的 Emscripten 安装。你是用 SDK 安装的吗?看起来emcc 找到了错误的clang(可能你已经安装了一个,出现在你的PATH 之前emcc 期望的那个),而不是通常随Emscripten 一起提供的clang 版本。

    您使用的是哪个操作系统?

    在 Linux 上检查 which clangecho $PATH 以确定哪个 clang 存在。

    尝试使用EMMAKEN_COMPILER=/path/to/emscripten-fastcomp/bin emcc test/hello.cc 调用emcc,这应该会覆盖上面的错误路径。

    还可以尝试使用 -v 选项调用 emcc 以获得详细输出。

    如果这些都不起作用,请发布这些命令的输出以及有关如何重现问题的信息。

    【讨论】:

      【解决方案3】:

      我在这里聚会迟到了,但对于其他有同样问题的人。

      使用 VS2015 的 CMake 文件构建的 emscripten-fastcomp 在 Windows 10 上运行。 emscripten 和 emscripten-fastcomp 都是从他们的 Github 存储库中克隆出来的。

      文档here 要么已过时,要么根本不正确。对于初学者,请尝试运行 emcc -v,即没有任何要编译的文件。

      R:\src\tools\emscripten>emcc -v
      

      这应该让你得到这个:

      > Welcome to Emscripten!
      > 
      > This is the first time any of the Emscripten tools has been run.
      > 
      > A settings file has been copied to ~/.emscripten, at absolute path:
      > C:\Users\user/.emscripten
      > 
      > It contains our best guesses for the important paths, which are:
      > 
      > LLVM_ROOT       = /usr/bin   
      > NODE_JS         = R:\apps\nodejs\node.exe   
      > EMSCRIPTEN_ROOT = R:\src\tools\emscripten
      > 
      > Please edit the file if any of those are incorrect.
      > 
      > This command will now exit. When you are done editing those paths,
      > re-run it.
      > 
      

      现在在

      中编辑 LLVM_ROOT 变量

      C:\Users\user\.emscripten

      这样默认的

      LLVM_ROOT = os.path.expanduser(os.getenv('LLVM') or '/usr/bin') # directory

      改成这样的

      LLVM_ROOT = os.path.expanduser(os.getenv('LLVM') or 'R:\\src\\tools\\emscripten-fastcomp\\build\\Debug\\bin') # directory.

      注意转义的反斜杠,标准的单反斜杠\ 不起作用。

      现在您应该能够像在

      中一样运行测试并获得合理的结果
      emcc -v tests/hello_world.cpp
      

      然后会喷出这样的东西:

      > R:\src\tools\emscripten>emcc -v tests/hello_world.cpp
      > INFO:root:generating system asset: is_vanilla.txt... (this will be
      > cached in "C:\Users\user\.emscripten_cache\is_vanilla.txt" for
      > subsequent builds) INFO:root: - ok INFO:root:(Emscripten: Running
      > sanity checks) INFO:root:(Emscripten: Running sanity checks) clang
      > version 3.9.0 (https://github.com/kripken/emscripten-fastcomp-clang
      > 60a7e9a9c22b67309e5b1258d38fadfa481a25d3)
      > (https://github.com/kripken/emscripten-fastcomp
      > 881bd352731d21c7117ad7e2ece347aacae83965) (emscripten 1.37.0 : 1.37.0)
      > Target: asmjs-unknown-emscripten Thread model: posix InstalledDir:
      > R:\src\tools\emscripten-fastcomp\build\Debug\bin 
      > "R:\\src\\tools\\emscripten-fastcomp\\build\\Debug\\bin\\clang++.exe"
      > -cc1 -triple asmjs-unknown-emscripten -emit-llvm-bc -emit-llvm-uselists -disable-free -main-file-name hello_world.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -no-integrated-as -mconstructor-aliases -v -dwarf-column-info -debugger-tuning=gdb -coverage-file "C:\\Users\\user\\AppData\\Local\\Temp\\tmpk4sar7\\hello_world_0.o"
      > -nostdsysteminc -nobuiltininc -resource-dir "R:\\src\\tools\\emscripten-fastcomp\\build\\Debug\\bin\\..\\lib\\clang\\3.9.0"
      > -D __EMSCRIPTEN_major__=1 -D __EMSCRIPTEN_minor__=37 -D __EMSCRIPTEN_tiny__=0 -D _LIBCPP_ABI_VERSION=2 -Werror=implicit-function-declaration -std=c++03 -fdeprecated-macro -fno-dwarf-directory-asm -fdebug-compilation-dir "R:\\src\\tools\\emscripten" -ferror-limit 19 -fmessage-length 80
      > -fobjc-runtime=gnustep -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -nobuiltininc -nostdsysteminc "-isystemR:\\src\\tools\\emscripten\\system\\include\\libcxx"
      > "-isystemR:\\src\\tools\\emscripten\\system\\lib\\libcxxabi\\include"
      > "-isystemR:\\src\\tools\\emscripten\\system\\include\\compat"
      > "-isystemR:\\src\\tools\\emscripten\\system\\include"
      > "-isystemR:\\src\\tools\\emscripten\\system\\include\\SSE"
      > "-isystemR:\\src\\tools\\emscripten\\system\\include\\libc"
      > "-isystemR:\\src\\tools\\emscripten\\system\\lib\\libc\\musl\\arch\\emscripten"
      > "-isystemR:\\src\\tools\\emscripten\\system\\local\\include"
      > "-isystemR:\\src\\tools\\emscripten\\system\\include\\SDL" -o
      > "C:\\Users\\user\\AppData\\Local\\Temp\\tmpk4sar7\\hello_world_0.o" -x
      > c++ tests/hello_world.cpp clang -cc1 version 3.9.0 based upon LLVM
      > 3.9.0 default target i686-pc-windows-msvc
      > #include "..." search starts here:
      > #include <...> search starts here:  R:\src\tools\emscripten\system\include\libcxx 
      > R:\src\tools\emscripten\system\lib\libcxxabi\include 
      > R:\src\tools\emscripten\system\include\compat 
      > R:\src\tools\emscripten\system\include 
      > R:\src\tools\emscripten\system\include\SSE 
      > R:\src\tools\emscripten\system\include\libc 
      > R:\src\tools\emscripten\system\lib\libc\musl\arch\emscripten 
      > R:\src\tools\emscripten\system\local\include 
      > R:\src\tools\emscripten\system\include\SDL End of search list.
      

      希望这可以节省其他人的节礼日头发撕裂。祝你好运。

      【讨论】:

        【解决方案4】:

        我在删除并重新安装 emsdk 后遇到了同样的问题

        解决方案:

        1. 打开一个新终端
        2. 转到 emsdk 安装目录
        3. 来源./emsdk_env.sh

        重置环境变量很关键。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2021-01-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-03-10
          • 1970-01-01
          • 2021-07-28
          相关资源
          最近更新 更多