How to debug an emscripten compilation error undefined symbol: ai_func

Solution for How to debug an emscripten compilation error undefined symbol: ai_func
is Given Below:

I am trying to compile an open source project from github /nutki/RFTG_WebApp
It uses emscriptem which I have never used before. And I am getting the following compilation errors when calling ‘make’, after debugging a bit I am seeing that the error is with ‘make rftg.js’.

$ make rftg.js
emcc -O3 rftg.c -o rftg.bc
emcc: warning: generating an executable with an object extension (.bc).  If you meant to build an object file please use `-c, `-r`, or `-shared` [-Wemcc]
wasm-ld: error: /tmp/emscripten_temp_oozlene1/rftg_0.o: undefined symbol: ai_func
wasm-ld: error: /tmp/emscripten_temp_oozlene1/rftg_0.o: undefined symbol: ai_func
wasm-ld: error: /tmp/emscripten_temp_oozlene1/rftg_0.o: undefined symbol: ai_func
wasm-ld: error: /tmp/emscripten_temp_oozlene1/rftg_0.o: undefined symbol: ai_func
wasm-ld: error: /tmp/emscripten_temp_oozlene1/rftg_0.o: undefined symbol: ai_func
wasm-ld: error: /tmp/emscripten_temp_oozlene1/rftg_0.o: undefined symbol: ai_func
wasm-ld: error: /tmp/emscripten_temp_oozlene1/rftg_0.o: undefined symbol: ai_func
wasm-ld: error: /tmp/emscripten_temp_oozlene1/rftg_0.o: undefined symbol: ai_func
wasm-ld: error: /tmp/emscripten_temp_oozlene1/rftg_0.o: undefined symbol: ai_func
wasm-ld: error: /tmp/emscripten_temp_oozlene1/rftg_0.o: undefined symbol: ai_func
emcc: error: '/home/user/Documents/enscripten/emsdk-main/upstream/bin/wasm-ld -o rftg.wasm /tmp/emscripten_temp_oozlene1/rftg_0.o -L/home/user/Documents/enscripten/emsdk-main/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten -lGL -lal -lhtml5 -lc -lcompiler_rt -lc++-noexcept -lc++abi-noexcept -ldlmalloc -lc_rt_wasm -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --import-undefined --strip-debug --export-if-defined=main --export-if-defined=stackSave --export-if-defined=stackRestore --export-if-defined=stackAlloc --export-if-defined=__wasm_call_ctors --export-if-defined=__errno_location --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-table -z stack-size=5242880 --initial-memory=16777216 --no-entry --max-memory=16777216 --global-base=1024' failed (returned 1)
Makefile:24: recipe for target 'rftg.bc' failed
make: *** [rftg.bc] Error 1

I looked at the ai_func, which is in the ai.c. I thought maybe it is being called before it is defined, tried moving it up to the top, didnt help.

prerequisites for this based on documentation are the cards.txt, campaign.txt, images.data, all of those are present (can be downloaded from the link in the readme). I have emscripten in path:

$ emcc --version
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 2.0.26 

I also have ImageMagick (and that part of compilation succeeds). and GTK+ 2.0 as well.

I am also able to compile the desktop version of the app via make rftg, it works. Compilation succeeds and I can run it. But when I try to create the web version it fails with the above error.

Id like to learn here. So Id like to get some pointers on how to approach this. Should I be trying to figure out why ai_func is undefined, or is that just the symptom and the error is actually elsewhere?

Thanks for any help!