Compiling is separate from linking. In C, a simple program calling malloc() and nothing else will include malloc.h. That results in a lot of definitions being brought in, but no implementations. Compiling will produce an object file. Again, no implementations for malloc(), it's an empty address waiting to be filled in. When you link, it all comes together, assuming the linker can find an implementation for malloc() (and there can be many implementations).
So compiling is rather straightforward. The harder part is automatic linking -- anything Java-specific that doesn't directly exist in JS (like long ints -- https://github.com/dcodeIO/long.js), or any calls to some library that also doesn't have a direct equivalent (like, say, some Swing draw commands), will have errors at link time. You can resolve that by creating an interface-equivalent version in JS and telling the linker about it, or you can go all the way to emulating a CPU and other hardware for an OS: https://win95.ajf.me/
Compiling is separate from linking. In C, a simple program calling malloc() and nothing else will include malloc.h. That results in a lot of definitions being brought in, but no implementations. Compiling will produce an object file. Again, no implementations for malloc(), it's an empty address waiting to be filled in. When you link, it all comes together, assuming the linker can find an implementation for malloc() (and there can be many implementations).
So compiling is rather straightforward. The harder part is automatic linking -- anything Java-specific that doesn't directly exist in JS (like long ints -- https://github.com/dcodeIO/long.js), or any calls to some library that also doesn't have a direct equivalent (like, say, some Swing draw commands), will have errors at link time. You can resolve that by creating an interface-equivalent version in JS and telling the linker about it, or you can go all the way to emulating a CPU and other hardware for an OS: https://win95.ajf.me/