5

What do I need to add to my CMakeLists.txt file such that below examples from here can still build?

I can generate the WASM with out any problems but have no idea what to add to my CMakeLists.txt to stop getting the error, when trying to just run the c code

fatal error: 'emscripten/emscripten.h' file not found #include <emscripten/emscripten.h>

I tried finding examples but sadly I found none.

#include <stdio.h>
#include <emscripten/emscripten.h>
    
int main(int argc, char ** argv) {
    printf("Hello World\n");
}
    
#ifdef __cplusplus
extern "C" {
#endif
    
EMSCRIPTEN_KEEPALIVE void myFunction(int argc, char ** argv) {
    printf("MyFunction Called\n");
}
    
#ifdef __cplusplus
}
#endif

My CMakeLists.txt is barebones at the moment and contains the following:

cmake_minimum_required(VERSION 3.17)
project(WASM)
    
set(CMAKE_CXX_STANDARD 14)
    
add_executable(WASM main.cpp)
6
  • I think you need to add emscripten/emscripten.h to add_executable list before main.cpp Commented Dec 27, 2020 at 14:05
  • 1
    So did you install emscripten? Commented Dec 27, 2020 at 14:11
  • @KamilCuk It cam with python 3.6 which I already had installed. Commented Dec 27, 2020 at 14:24
  • 1
    So where is empcripten.h file installed? Commented Dec 27, 2020 at 14:26
  • @KamilCuk I found it using find command at usr/local/Cellar/emscripten/2.0.10/libexec/system/include/emscripten/emscripten.h Commented Dec 27, 2020 at 14:30

1 Answer 1

3

Be sure to use the emsdk provided cmake wrapper script called emcmake upon configuration. The script takes care of setting up the compilation enviroment for emsdk, i.e.:

   $ mkdir build
   $ cd build
   $ /path/to/emcmake cmake ..
   $ make

Also see the following Github issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.