emscripten-core / emsdk

Emscripten SDK
http://emscripten.org
Other
2.96k stars 676 forks source link

Compiling C++ Project that results in mutiple executables #1296

Open ganeshkbhat opened 10 months ago

ganeshkbhat commented 10 months ago

I am trying to Compile C++ Project that results in multiple executables https://www.7-zip.org/. The make command generates o files, a single 7z.a file and multiple executables normally without issues. However, when I am trying to use the emcc the command emcc -O2 a.o b.o -o project.js or the emcc project.o libstuff.a -o final.html from the https://emscripten.org/docs/tools_reference/emcc.html#emccdoc is giving me errors saying xxx.o file format cannot be recognised.

What I wish to be doing is use the xx.o file and yy.o file which uses lib7z.a produces xx.exe and yy.exe executable to xx.wasm and yy.wasm respectively to export the functions of xx.exe and yy.exe files appropriately and not really the base functions of lib7z.a directly many of which are then used in a usable mode in the .c and .h files that makes the .exe files.

when the lib7z.a file created to create a lib7z.wasm file generates a lib7z.wasm file but the usage has become a lot more messy because the exported functions are not clear and not documented well. I am also unsure if all the executable functions of all 7z project's different executables exist in a directly usable format inside lib7z.wasm as well.

Commands:

# Compile project to project.o

emmake make

# Link the library and code together.
emcc project.o libstuff.a -o final.html
####FAILS

Alternatively


emmake make

# Link the library and code together.
emcc -02 a.o b.o -o project.js
####FAILS
sbc100 commented 10 months ago

If you want to create a static library such as lib7z.a when you need to use emar to create it, and not emcc.

The emcc project.o libstuff.a -o final.html example you give should work assuming things are setup correctly. Please share the full error message if you need more help with that.

If you see errors like xxx.o file format cannot be recognised that probably means have not built xxx.o with emcc but instread with the host compiler (e.g. clang or gcc). You need to make sure you use emcc when building the 7zip project.