Live data from Hacker News

Show HN: How to compile C/C++ for WASM, pure Clang, no libs, no framework

github.com

41–44 of 44 posts

Re: Show HN: How to compile C/C++ for WASM, pure Clang, no libs, no framework

#41

Meta comment: your committer email is not in sync with your profile so the Github UI shows the commits attached to a blank user. If you want these two in sync you can either add your committing email to your Github account or you can modify your git config to use your Github email as your commit email. Or you can just leave it as is too. :)

thx, fixed (hopefully)

Re: Show HN: How to compile C/C++ for WASM, pure Clang, no libs, no framework

#42

I do a similar thing for my side project. Note that the clang that comes with Xcode (Apple clang) doesn’t have wasm support.

Thanks for warning! Anyway, I just got a new Mac, but I started with installing brew and then install CLANG comes with brew.

I have had more headache with my not-too-but-old-enough Linux systems, 2 of 2 failed: one got stuck when linking (yes, the linker hangs!), another one produced perfect size .wasm output, with... wait for it... full of zero bytes. Full story here: https://stackoverflow.com/questions/71573019/cant-compile-to...

Re: Show HN: How to compile C/C++ for WASM, pure Clang, no libs, no framework

#43
post #31

Is there a similar example for C?

Just rename the file and remove extern "C" stuff :). It started as C, but then I switched to CPP, to see, can I export simple symbol names, not mangled ones C++ produces.

Anyway, you can use C++ as C, using just as many C++ features as you need. (Insert "throwing the guy out of window" meme picture here.)

Re: Show HN: How to compile C/C++ for WASM, pure Clang, no libs, no framework

#44
post #7

This looks good! In my experience the hardest part for compiling WebAssembly is third party dependencies. Getting arbitrary libraries to build can be rather challenging.

Especially - ofcoz' maybe I'm wrong -, that there're not too many C/C++ libs for WASM, always Rust comes up.
Post reply on HN