Compiling my app to WebAssembly--Can't generate .wasm file

(Osman Zakir) #1

Hi, everyone.

I created a C++ webserver application using Boost.Beast, which is a HTTP/S and WebSockets library relying on Boost.Asio for the networking functionality, and I’ve been trying to compile it to WebAssembly with no success (I can generate .o and .js files, but not .wasm files for it).

My app is a currency converter that uses a Google Maps GUI. It displays an info window on the map which is centered on the user’s location should he/she give permission for the browser to use their location via geolocation. It is also possible to search for places and center the map on a place by clicking on it. The info window shows an HTML form for taking input where the default base currency is USD and the “to” currency is by default the currency of the place the map is centered on. The C++ app serves up HTML, CSS and JavaScript files I wrote myself, and it also acts as a web client to query the currency API I’m using for conversion rates. I’ve put the source code for the app on GitHub, here: .

I tried using this command to compile my app to WebAssembly:

em++ -std=c++17 -Wall -pedantic -D variant_CONFIG_SELECT_VARIANT=variant_VARIANT_NONSTD -I C:/Jinja2Cpp/install_x64/include -I C:/json/single_include -I C:/boost_1_68_0/ -I C:/Users/Osman/emsdk/emscripten/1.38.18/system/include/ currency_converter.cpp -L C:/Jinja2Cpp/install_x64/lib/static/jinja2cpp.lib -L C:/boost_1_68_0/lib64-msvc-14.1/libboost_system-vc141-mt-x64-1_68.lib -lpthread -o currency_converter.js -o currency_converter.o currency_converter.js -s WASM=1 -s DISABLE_EXCEPTION_CATCHING=0 -s USE_PTHREADS=1

And I also tried to link the .o file to WebAssembly by doing

em++ currency_converter.o -o currency_converter.js -s WASM=1 -s DISABLE_EXCEPTION_CATCHING=0 -s USE_PTHREADS=1

And when that didn’t work I even tried putting the -s flags earlier in the command and providing -I and -L commands, neither of which worked. What am I doing wrong? Please help. Thanks in advance.