[Solved] emcc error: error: LLVM_ROOT is not defined

When using EMCC to compile code, an error is reported:

> emcc hello.c -s WASM=1 -o hello.html
emcc: error: LLVM_ROOT is not defined in /

The reason why I encountered this problem is that I did not execute the activation statement after installing emsdk:

> emsdk activate latest
> source "/root/code/emsdk/emsdk_env.sh"
# After activation, you will be prompted to configure the environment, this step is also very important, otherwise it will be activated for nothing

Also be careful not to forget to activate the other two components:

> emsdk activate binaryen-main-64bit emscripten-main-64bit
> source "/root/code/emsdk/emsdk_env.sh"

After activation, don’t forget to configure environment variables
if you encounter similar problems later, you can first:

  1. Check whether the module in emsdk is activated or not?
  2. Check whether the source environment is variable or not?

If you can’t confirm, you can redo the above two steps to see if the problem is still there.

Read More: