2015-04-17 156 views
2

當我試圖用EMCC編譯C代碼爲JavaScript,我收到以下錯誤:如何讓emcc工作?

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?

回答

1

這看起來像Emscripten的配置錯誤。你用SDK安裝了嗎?它看起來像emcc找到了錯誤的clang(可能是你已經安裝的一個,出現在PATH之前,emcc預計),而不是Emscripten通常附帶的clang版本。

你在哪個操作系統上?

在Linux上檢查which clangecho $PATH以確定哪個clang存在。

嘗試調用emcc與:EMMAKEN_COMPILER=/path/to/emscripten-fastcomp/bin emcc test/hello.cc這應該覆蓋上面的錯誤路徑。

也試着調用emcc-v選項來獲得詳細的輸出。

如果這些都不起作用,請發佈這些命令的輸出以及有關如何重現問題的信息。

2

我在從源手動構建Emscripten時解決了同樣的錯誤。

Emscripten使用自己的LLVM分支 - Fastcomp; 按照說明here從源代碼構建。然後編輯~/.emscriptenLLVM_ROOT這樣

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

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

1

我遲到了這裏的黨,但對於其他人同樣的問題(一個或多個)。

在Windows 10上使用emscripten-fastcomp在VS2015中使用CMake文件構建。 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. 

希望這樣可以節省別人的節禮日頭髮撕裂。祝你好運。