It’s basically the title, but here is some context:
Recently I’ve been trying to link a C library to a D main in WASM, and successfully produced “hello” to browser console (yay).
This required me to compile my hello_lib.c and hello_world.d to a .o file using a D compiler (ldc), then .o to .wasm with emscripten.
I had some problems at the linking stage, which is the reason I had to use this whole toolchain. If I had used only ldc, it would complain about undefined ‘printf’ from stdio. (This is not my question, it works normally if you compile for native, just not for WASM. It is solved already.)
The thing is, if up to point where ldc generates a .o file it still doesn’t know about ‘printf’ in stdio, how can it produce whole code optimizations ever? (If you use “-c” flag, ldc produces said .o files and does not complain about ‘printf’.)
I always write my code in many libs, just to keep things organized, and I know this won’t be a performance hog or anything like that, still, it seems like missed opportunity for the compiler.
Shouldn’t it “glue” the code in a huge file first, then make optimizations after that? I though that was what static libraries where all about.
Matheus de Moraes Peixoto is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.