I use emcc to complie a C++ code into js. But how to pass args to C++ code?
#include<iostream>
int main(int argc, char** argv) {
if (argc > 1)
printf("%s", argv[1]);
}
build :
emcc ./test.cpp -sENVIRONMENT=shell -o test.js
pass commadline args into c code
It seems that this stackexchange answer is similar to your use-case:
Place
before you run your function.
Documentation reference
Edit:
So, I finally had time to install
d8, and I made it work.For me, in the generated
test.js, there is this line:You have to place the arguments before this, so it should look like:
You then compile with
emccand run withd8. I got another error because I did not end myprintfcall without a newline, so the output was not printing, a thing that seems to also happen in your code. Fortunately, there was an error message about the stdout not fully flushing, so I got to understand that was the problem.