How We Compile Multiple C++ class through .bat file in windows OS

622 views
Skip to first unread message

Satish Y

unread,
Jul 14, 2021, 6:21:42 AM7/14/21
to emscripten-discuss
Hello Guys,
 I have multiple c++ classes in my android project. I successfully  converted these file in .wasm file with the help of emscripten so that i can use it, one of my java script project . But to get WASM file, I used to compile one class at a time one by one  then after create the webassembly file through command (emcmdprompt). So i want to generate this Webassembly file in one go. So please sugget that how i can generate.

I have more that 10 CPP classes, and the Command which i used to compile cpp class through "emcmdprompt" terminal one by one is  

emcc -O3 --bind -c  fileName1.cpp
emcc -O3 --bind -c  fileName2.cpp
emcc -O3 --bind -c  fileName3.cpp
.......
......

and once the object file created then again i run one more command on "emcmdprompt" terminal to generate .wasm file

emcc -O3 --bind  fileName1.o  fileName2.o  fileName3.o -o script.js -s ALLOW_MEMORY_GROWTH=1

so please suggest how i can write all these command in single file and run in one go, instead of manually running one by one. 

Thanks

Floh

unread,
Jul 14, 2021, 8:01:00 AM7/14/21
to emscripten-discuss
The easiest way is to simply place all cpp files into one emcc call:

emcc -O3 --bind filename1.cpp filename2.cpp ... -o script.js -s ALLOW_MEMORY_GROWTH=1

The next step from this would be using a build tool like cmake or GNU Make, but that's probably overkill for your use case (unless you have dozens of source file).

Satish Y

unread,
Jul 14, 2021, 9:05:04 AM7/14/21
to emscripten-discuss
Thanks for you reply but this technique is not working  .

Floh

unread,
Jul 14, 2021, 10:15:22 AM7/14/21
to emscripten-discuss
> but this technique is not working  .

That's strange, what errors are you seeing?

Satish Y

unread,
Jul 17, 2021, 8:35:22 AM7/17/21
to emscripten-discuss
Hello Floh,
 My C++ files are in different packages like some files are inside folder1, folder2, folder3 and folder4 and some are in parent directory (like abc.cpp & def.cpp .......) as you can see in below screenshot. So when I ran the emcc command I think emscripten compiler is confuse with  C++ file path. So how I specify C++ files name with respective folder.



emcc -O3 --bind folder1/aa1.cpp aa2.cpp aa3.cpp aa4.cpp folder2/bb1.cpp folder3/cc1.cpp folder4/dd4.cpp abc.cpp  def.cpp -o script.js -s ALLOW_MEMORY_GROWTH=1

when i ran the above command got issue -> emcc: error: aa2.cpp: No such file or directory ("aa2.cpp" was expected to be an input file, based on the commandline arguments provided)



emscriptenDemo.png

Floh

unread,
Jul 17, 2021, 10:46:52 AM7/17/21
to emscripten-discuss
This works here. You don't provide a path before aa2.cpp, aa3.cpp and aa4.cpp, are those not living in folders? You need to provide the path relative to the "current working directory" (e.g. from where emcc is started).

Satish Y

unread,
Jul 18, 2021, 9:08:32 AM7/18/21
to emscripten-discuss
Yes aa1.cpp, aa2.cpp, aa3.cpp and aa4.cpp are living inside the folder1.


emcc -O3 --bind folder1/aa1.cpp aa2.cpp aa3.cpp aa4.cpp folder2/bb1.cpp folder3/cc1.cpp folder4/dd4.cpp abc.cpp  def.cpp -o script.js -s ALLOW_MEMORY_GROWTH=1
folder1/aa1.cpp aa2.cpp aa3.cpp aa4.cpp 
folder2/bb1.cpp
folder3/cc1.cpp 
folder4/dd4.cpp 
abc.cpp  
def.cpp 


Floh

unread,
Jul 18, 2021, 6:36:14 PM7/18/21
to emscripten-discuss
> Yes aa1.cpp, aa2.cpp, aa3.cpp and aa4.cpp are living inside the folder1.

In that case you need to put the folder name in front of each filename:

emcc -O3 --bind folder1/aa1.cpp folder1/aa2.cpp folder1/aa3.cpp ...

...and so on.

Satish Y

unread,
Jul 19, 2021, 8:53:43 AM7/19/21
to emscripten-discuss
Thank you, it's working. So could you please suggest instead of executing command on  "emcmdprompt" to generate .wasm file,  Can we not write command in any file and easily generate .wasm file ??
Reply all
Reply to author
Forward
0 new messages