emscripten icon indicating copy to clipboard operation
emscripten copied to clipboard

failed to compile

Open AHaliq opened this issue 4 years ago • 0 comments

Hi, can you assist on an issue im having.

Project Setup

Heres my project for reference: https://github.com/AHaliq/wasmtest

I've created a create-react-app and ran npm run eject and updated the config/webpack.config.js accordingly for your loader. I've added a cpp file in my src as such

#include <emscripten.h>

EMSCRIPTEN_KEEPALIVE
int add(int x, int y) {
  return x + y;
}

and in index.js

import { add } from './hello_world.cpp';
console.log(add(5,10));

Everything seems fine but I'm getting unable to compile error

The issue

Failed to compile.

./src/hello_world.cpp
Error: Command failed: emcc hello_world.cpp -O3 -s WASM=1 -s MODULARIZE=1
warning: honoring legacy environment variable `NODE`.  Please switch to using `EM_NODE_JS` instead`
hello_world.cpp:1:8: error: expected template
export default __webpack_public_path__ + "static/media/hello_world.905deec9.cpp";
       ^
hello_world.cpp:1:8: error: expected unqualified-id
2 errors generated.
emcc: error: '/Users/haliq/Desktop/zkp_research/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -DEMSCRIPTEN -fignore-exceptions -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -D__EMSCRIPTEN_major__=2 -D__EMSCRIPTEN_minor__=0 -D__EMSCRIPTEN_tiny__=25 -D_LIBCPP_ABI_VERSION=2 -Dunix -D__unix -D__unix__ -Werror=implicit-function-declaration -Xclang -iwithsysroot/include/SDL --sysroot=/Users/haliq/Desktop/zkp_research/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/compat -O3 hello_world.cpp -c -o /var/folders/f6/128r_qx57953hch5znq5npq00000gn/T/emscripten_temp_nl9vsukn/hello_world_0.o' failed (returned 1)

running the commands individually however works fine

emcc hello_world.cpp -O3 -s WASM=1 -s MODULARIZE=1

and

/Users/haliq/Desktop/zkp_research/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -DEMSCRIPTEN -fignore-exceptions -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -D__EMSCRIPTEN_major__=2 -D__EMSCRIPTEN_minor__=0 -D__EMSCRIPTEN_tiny__=25 -D_LIBCPP_ABI_VERSION=2 -Dunix -D__unix -D__unix__ -Werror=implicit-function-declaration -Xclang -iwithsysroot/include/SDL --sysroot=/Users/haliq/Desktop/zkp_research/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/compat -O3 hello_world.cpp -c -o ./hello_world_0.o

runs fine

AHaliq avatar Jul 15 '21 09:07 AHaliq