emscripten-core / emscripten-core/emscripten

Cannot build an existing project due to picking up system include as oppose to emscripten include

Open
#16,351 10 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Hi

When trying to build an existing cmake project with emscripten, I get issues because some includes are picked up from `/usr/include/linux/` instead of `/install/emsdk/upstream/emscripten/cache/sysroot/include/`

I created an issue, in case it's a known problem.

**I run cmake as **

```
emcmake cmake .. -G Ninja -DCMAKE_TOOLCHAIN_FILE='../cmake/toolchain/emcc.cmake'
```

**Error**

```
In file included from /home/dyarosh/space/eve/test/tts/tts.hpp:25:
In file included from /install/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/iostream:37:
In file included from /install/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/ios:214:
In file included from /install/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/__locale:15:
In file included from /install/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/string:522:
In file included from /install/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/algorithm:653:
In file included from /install/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/functional:500:
In file included from /install/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/__functional/function.h:20:
In file included from /install/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/__memory/shared_ptr.h:35:
In file included from /install/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/atomic:582:
In file included from /install/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/__threading_support:16:
In file included from /usr/include/errno.h:28:
In file included from /usr/include/bits/errno.h:26:
/usr/include/linux/errno.h:1:10: fatal error: 'asm/errno.h' file not found
#include
```

** Possible reason **

In the compile commands I can see: `-isystem /usr/include`. This seems wrong but I don't see where it can be coming from.

Full command

```
/install/emsdk/upstream/emscripten/em++ -I/home/dyarosh/space/eve/test -I/home/dyarosh/space/eve/examples -I/home/dyarosh/space/eve/include -isystem /usr/include -DEVE_NO_FORCEINLINE -O3 -std=c++20 -Werror -Wall -Wpedantic -Wextra -Winvalid-pch -fpch-instantiate-templates -Xclang -emit-pch -Xclang -include -Xclang /home/dyarosh/space/eve/build_emcc/CMakeFiles/bench_pch.dir/cmake_pch.hxx -x c++-header -o CMakeFiles/bench_pch.dir/cmake_pch.hxx.pch -c /home/dyarosh/space/eve/build_emcc/CMakeFiles/bench_pch.dir/cmake_pch.hxx.cxx
```

**Toolchain file**

I added `CMAKE_FIND_ROOT_PATH_MODE*` things after what I found on the internet when I encountered the problem.

```
set(CMAKE_C_COMPILER emcc )
set(CMAKE_CXX_COMPILER em++ )

set(CMAKE_CXX_FLAGS "-DEVE_NO_FORCEINLINE ${EVE_OPTIONS}" )

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

set(CMAKE_CROSSCOMPILING_CMD ${PROJECT_SOURCE_DIR}/cmake/toolchain/run_wasm.sh )
```

run_wasm is just `node $@`

**Version of emscripten/emsdk:**

```
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.2 (a77b559a8b40b7e89fc8c17e41034128df9543e4)
clang version 14.0.0 (https://github.com/llvm/llvm-project 782c0dd1a1c235afb09a34e7da4a1267ead14765)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /install/emsdk/upstream/bin
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.