Sometimes when I am building a larger project with Qt for WebAssembly, I get this type of message:
wasm-ld: error: initial memory too small, 17553264 bytes needed
and the build fails.
This means that you need to tell Emscripten compiler to allocate more than the standard 1GB initial memory.
Qt allows you to specify to add more initial memory by using QMAKE_TOTAL_MEMORY in your pro file.
So it makes sense to add something like this:
BUT the result is:
shared:ERROR: For wasm, TOTAL_MEMORY must be a multiple of 64KB, was 17553264
grrrr... ok, what if we find a multiple of 64?
17553264 / 64 = 274,269.95
We need a whole number, so lets round up to the next whole number.
274270 * 64 = 17553280
But no. That doesn't work either:
shared:ERROR: For wasm, TOTAL_MEMORY must be a multiple of 64KB, was 17553280
The answer is that a KB is 1024 bytes, so 64 * 1024 = 65536 bytes
So let's find the closest whole number multiple of 64 KB (65536)
17553264 / 65536 = 267.841...
so let's try 268
268 * 65536 = 17563648
and this now builds, and hopefully runs!