How to include <emscripten/emscripten.h>

Viewed 2505

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)
1 Answers

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.

Related