I don't see where setEnvironmentVar is defined in JS? I'd expect something
like

var setEnvironmentVar = cwrap('setEnvironmentVar', ..);
setEnvironmentVar(..);

Might be helpful to look at the examples in the test suite (e.g.
test_ccall).

On Sun, Apr 14, 2019 at 12:26 AM <[email protected]> wrote:

> Hello,
> I have problems with emcc and node.js, when I use cwrap or ccall.
> My information source is at
>
>
> https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html
>
> I tried several approaches, but I did not succeed.
> The C program with my test follows:
>
> ---------- begin test program tst262.c ----------
> #include "stdio.h"
> #include "string.h"
> #include "emscripten.h"
>
>
> extern void setEnvironmentVar (char *key, char *value)
>
>   { /* setEnvironmentVar */
>     printf("setEnvironmentVar(\"%s\", \"%s\")\n", key, value);
>   } /* setEnvironmentVar */
>
>
> int main (int argc, char *argv[])
>
>   { /* main */
>     printf("begin main\n");
>     setEnvironmentVar("", "");
>     EM_ASM(
>       // console.log(process.env);
>       let setEnvVar = Module.cwrap('setEnvironmentVar', 'number',
> ['string', 'string']);
>       Object.keys(process.env).forEach(function(key) {
>         let val = process.env[key];
>         console.log(key);
>     setEnvVar(key, val);
>       });
>     );
>     printf("end main\n");
>   } /* main */
> ---------- end test program tst262.c ----------
>
> Compiling and starting this program does not work:
>
>   myPrompt> emcc tst262.c -o tst262.js -s
> EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]'
>   myPrompt> node tst262.js
>   begin main
>   setEnvironmentVar("", "")
>   SHELL
>   Assertion failed: Cannot call unknown function setEnvironmentVar, make
> sure it is exported
>   Assertion failed: Cannot call unknown function setEnvironmentVar, make
> sure it is exported
>   exception thrown: abort("Assertion failed: Cannot call unknown function
> setEnvironmentVar, make sure it is exported") at Error
>       at jsStackTrace
> (/run/media/tm/disk2_460GiB/home/tm/seed7_5/src/tst262.js:1152:13)
>       at stackTrace
> (/run/media/tm/disk2_460GiB/home/tm/seed7_5/src/tst262.js:1169:12)
>       at abort
> (/run/media/tm/disk2_460GiB/home/tm/seed7_5/src/tst262.js:2338:44)
>       at assert
> (/run/media/tm/disk2_460GiB/home/tm/seed7_5/src/tst262.js:583:5)
>       at getCFunc
> (/run/media/tm/disk2_460GiB/home/tm/seed7_5/src/tst262.js:590:3)
>       at ccall
> (/run/media/tm/disk2_460GiB/home/tm/seed7_5/src/tst262.js:621:14)
>       at /run/media/tm/disk2_460GiB/home/tm/seed7_5/src/tst262.js:644:12
>       at /run/media/tm/disk2_460GiB/home/tm/seed7_5/src/tst262.js:1708:210
>       at Array.forEach (<anonymous>)
>       at Array.ASM_CONSTS
> (/run/media/tm/disk2_460GiB/home/tm/seed7_5/src/tst262.js:1708:140)
>   myPrompt>
>
> When I export setEnvironmentVar as suggested I get:
>
>   myPrompt> emcc tst262.c -o tst262.js -s
> EXPORTED_FUNCTIONS='["_setEnvironmentVar"]' -s
> EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]'
>   myPrompt> node tst262.js
>   myPrompt>
>
> As you can see: The program terminates immediate. If I use ccall
> instead of cwrap I get the same error. Allocating pointers for
> the strings and calling the function direct from JavaScript,
> as suggested by the documentation, fails also. It just cannot
> find the function setEnvironmentVar. Using underscore (_) at
> various places did also not help.
>
> What is necessary to make ccall and cwrap work?
>
> Many thanks in advance for your help.
>
> Regards,
> Thomas Mertes
>
> --
> Seed7 Homepage:  http://seed7.sourceforge.net
> Seed7 - The extensible programming language: User defined statements
> and operators, abstract data types, templates without special
> syntax, OO with interfaces and multiple dispatch, statically typed,
> interpreted or compiled, portable, runs under linux/unix/windows.
>
> --
> You received this message because you are subscribed to the Google Groups
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to