diff --git a/site/source/docs/getting_started/FAQ.rst b/site/source/docs/getting_started/FAQ.rst index 883040f0f..19cb2f1c6 100644 --- a/site/source/docs/getting_started/FAQ.rst +++ b/site/source/docs/getting_started/FAQ.rst @@ -255,6 +255,11 @@ To make sure a C function remains available to be called from normal JavaScript, ./emcc -s EXPORTED_FUNCTIONS="['_main', '_my_func']" ... +.. note:: + + `EXPORTED_FUNCTIONS` affects compilation to JavaScript. If you first compile to an object file, + then compile the object to JavaScript, you need that option on the second command. + If your function is used in other functions, LLVM may inline it and it will not appear as a unique function in the JavaScript. Prevent inlining by defining the function with :c:type:`EMSCRIPTEN_KEEPALIVE`: :: void EMSCRIPTEN_KEEPALIVE yourCfunc() {..} diff --git a/site/source/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.rst b/site/source/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.rst index 6c4869469..c0966103a 100644 --- a/site/source/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.rst +++ b/site/source/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.rst @@ -65,6 +65,13 @@ home directory:: ./emcc tests/hello_function.cpp -o function.html -s EXPORTED_FUNCTIONS="['_int_sqrt']" +.. note:: + + `EXPORTED_FUNCTIONS` affects compilation to JavaScript. If you first compile to an object file, + then compile the object to JavaScript, you need that option on the second command. If you do + it all together as in the example here (source straight to JavaScript) then this just works, + of course. + After compiling, you can call this function with :js:func:`cwrap` using the following JavaScript::