Tag Archives: webassembly

[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.

[Solved] VScode Error: build constraints exclude all Go files in syscall\js

When developing golang webassembly in vscode, an error is reported when importing the package. The code is as follows:

// main.go
package main

import "syscall/js"

func main() {
	alert := js.Global().Get("alert")
	alert.Invoke("Hello World!")
}

The error information is as follows:

could not import syscall/js (cannot find package "syscall/js" in any of 
	E:\Go\src\syscall\js (from $GOROOT)
	F:\go\Gopath\src\syscall\js (from $GOPATH))
error while importing syscall/js: build constraints exclude all Go files in E:\Go\src\syscall\js

The solution is as follows:

Open setting and enter go tools env

Open settings.JSON file, write in the file:

{
  "go.toolsEnvVars": {
    "GOOS":"js",
    "GOARCH":"wasm"
  }
}

Then reopen vscode.