Bulid Error: Emscripten on Windows

Emscripten on Windows
Hi guys,
I want to build Urho3D with emscripten on windows, but I have some troubles. Pls give me some advise.

The build detals as follows:
1.Install emsdk 2.0.8
2.Install mingw by MinGW Installer
3.run emcmdprompt.bat
4.Build tree D:\Urho3D>script\cmake_emscripten.bat d:\web01 -D URHO3D_LUA=0 -D URHO3D_PACKAGING=0
5.D:\Urho3D>cd …/web01
D:\web01>emmake make

Error as follows:

D:\Urho3D\Source\Urho3D\Core\ProcessUtils.cpp: In function ‘void Urho3D::PrintUnicode(const Urho3D::String&, bool)’:
D:\Urho3D\Source\Urho3D\Core\ProcessUtils.cpp:224:29: error: ‘_fileno’ was not declared in this scope
if (!isatty(fileno(out)))
^
CMakeFiles\PackageTool.dir\build.make:225: recipe for target 'CMakeFiles/PackageTool.dir/D
/Urho3D/Source/Urho3D/Core/ProcessUtils.cpp.obj’ failed
mingw32-make[5]: *** [CMakeFiles/PackageTool.dir/D
/Urho3D/Source/Urho3D/Core/ProcessUtils.cpp.obj] Error 1
CMakeFiles\Makefile2:117: recipe for target ‘CMakeFiles/PackageTool.dir/all’ failed
mingw32-make[4]: *** [CMakeFiles/PackageTool.dir/all] Error 2
Makefile:134: recipe for target ‘all’ failed
mingw32-make[3]: *** [all] Error 2
Source\Tools\CMakeFiles\PackageTool.dir\build.make:84: recipe for target ‘Source/Tools/PackageTool-prefix/src/PackageTool-stamp/PackageTool-build’ failed
mingw32-make[2]: *** [Source/Tools/PackageTool-prefix/src/PackageTool-stamp/PackageTool-build] Error 2
CMakeFiles\Makefile2:1988: recipe for target ‘Source/Tools/CMakeFiles/PackageTool.dir/all’ failed
mingw32-make[1]: *** [Source/Tools/CMakeFiles/PackageTool.dir/all] Error 2
Makefile:154: recipe for target ‘all’ failed
mingw32-make: *** [all] Error 2

– Build files have been written to: D:/web01/Source/Tools/PackageTool-prefix/src/PackageTool-build
[ 89%] Performing build step for ‘PackageTool’
[ 2%] Building C object host/LibCpuId/CMakeFiles/LibCpuId.dir/src/asm-bits.c.obj
[ 4%] Building C object host/LibCpuId/CMakeFiles/LibCpuId.dir/src/cpuid_main.c.obj
[ 6%] Building C object host/LibCpuId/CMakeFiles/LibCpuId.dir/src/libcpuid_util.c.obj
[ 8%] Building C object host/LibCpuId/CMakeFiles/LibCpuId.dir/src/msrdriver.c.obj
[ 10%] Building C object host/LibCpuId/CMakeFiles/LibCpuId.dir/src/rdmsr.c.obj
[ 12%] Building C object host/LibCpuId/CMakeFiles/LibCpuId.dir/src/rdtsc.c.obj
[ 14%] Building C object host/LibCpuId/CMakeFiles/LibCpuId.dir/src/recog_amd.c.obj
[ 16%] Building C object host/LibCpuId/CMakeFiles/LibCpuId.dir/src/recog_intel.c.obj
[ 18%] Linking C static library libLibCpuId.a
[ 18%] Built target LibCpuId
[ 20%] Building C object host/LZ4/CMakeFiles/LZ4.dir/lz4.c.obj
[ 22%] Building C object host/LZ4/CMakeFiles/LZ4.dir/lz4hc.c.obj
[ 25%] Linking C static library libLZ4.a
[ 25%] Built target LZ4
[ 27%] Building CXX object CMakeFiles/PackageTool.dir/PackageTool.cpp.obj
[ 29%] Building CXX object CMakeFiles/PackageTool.dir/D_/Urho3D/Source/Urho3D/Container/Allocator.cpp.obj
[ 31%] Building CXX object CMakeFiles/PackageTool.dir/D_/Urho3D/Source/Urho3D/Container/HashBase.cpp.obj
[ 33%] Building CXX object CMakeFiles/PackageTool.dir/D_/Urho3D/Source/Urho3D/Container/RefCounted.cpp.obj
[ 35%] Building CXX object CMakeFiles/PackageTool.dir/D_/Urho3D/Source/Urho3D/Container/Str.cpp.obj
[ 37%] Building CXX object CMakeFiles/PackageTool.dir/D_/Urho3D/Source/Urho3D/Container/VectorBase.cpp.obj
[ 39%] Building CXX object CMakeFiles/PackageTool.dir/D_/Urho3D/Source/Urho3D/Core/Context.cpp.obj
[ 41%] Building CXX object CMakeFiles/PackageTool.dir/D_/Urho3D/Source/Urho3D/Core/EventProfiler.cpp.obj
[ 43%] Building CXX object CMakeFiles/PackageTool.dir/D_/Urho3D/Source/Urho3D/Core/Mutex.cpp.obj
[ 45%] Building CXX object CMakeFiles/PackageTool.dir/D_/Urho3D/Source/Urho3D/Core/Object.cpp.obj
[ 47%] Building CXX object CMakeFiles/PackageTool.dir/D_/Urho3D/Source/Urho3D/Core/ProcessUtils.cpp.obj
D:\Urho3D\Source\Urho3D\Core\ProcessUtils.cpp: In function ‘void Urho3D::PrintUnicode(const Urho3D::String&, bool)’:
D:\Urho3D\Source\Urho3D\Core\ProcessUtils.cpp:224:29: error: ‘_fileno’ was not declared in this scope
if (!isatty(fileno(out)))
^
CMakeFiles\PackageTool.dir\build.make:225: recipe for target 'CMakeFiles/PackageTool.dir/D
/Urho3D/Source/Urho3D/Core/ProcessUtils.cpp.obj’ failed
mingw32-make[5]: *** [CMakeFiles/PackageTool.dir/D
/Urho3D/Source/Urho3D/Core/ProcessUtils.cpp.obj] Error 1
CMakeFiles\Makefile2:117: recipe for target ‘CMakeFiles/PackageTool.dir/all’ failed
mingw32-make[4]: *** [CMakeFiles/PackageTool.dir/all] Error 2
Makefile:134: recipe for target ‘all’ failed
mingw32-make[3]: *** [all] Error 2
Source\Tools\CMakeFiles\PackageTool.dir\build.make:84: recipe for target ‘Source/Tools/PackageTool-prefix/src/PackageTool-stamp/PackageTool-build’ failed
mingw32-make[2]: *** [Source/Tools/PackageTool-prefix/src/PackageTool-stamp/PackageTool-build] Error 2
CMakeFiles\Makefile2:1988: recipe for target ‘Source/Tools/CMakeFiles/PackageTool.dir/all’ failed
mingw32-make[1]: *** [Source/Tools/CMakeFiles/PackageTool.dir/all] Error 2
Makefile:154: recipe for target ‘all’ failed
mingw32-make: *** [all] Error 2

What version of mingw are you using?

C:\Users\pc>gcc -v
specs
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/mingw/bin/…/libexec/gcc/mingw32/6.3.0/lto-wrapper.exe
mingw32
…/src/gcc-6.3.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --target=mingw32 --with-gmp=/mingw --with-mpfr --with-mpc=/mingw --with-isl=/mingw --prefix=/mingw --disable-win32-registry --with-arch=i586 --with-tune=generic --enable-languages=c,c++,objc,obj-c++,fortran,ada --with-pkgversion=‘MinGW.org GCC-6.3.0-1’ --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --with-libiconv-prefix=/mingw --with-libintl-prefix=/mingw --enable-libstdcxx-debug --enable-libgomp --disable-libvtv --enable-nls
win32
gcc 6.3.0 (MinGW.org GCC-6.3.0-1)

Try using mingw-w64, I think there are some problems using the other version in building Urho.

Hi, now I have met errors as follows, Probably what’s the reason?

Install the project…
– Install configuration: “Release”
– Installing: D:/w00/bin/tool/PackageTool.exe
[ 87%] Completed ‘PackageTool’
[ 87%] Built target PackageTool
[ 87%] Checking and packaging resource directories
Packaging D:/Urho3D-1.7/bin/CoreData…
Packaging D:/Urho3D-1.7/bin/Data…
[ 87%] Built target RESOURCE_CHECK
[ 87%] Generating shared data file -s FORCE_FILESYS
Remember to build the main file with TEM=1 so that it includes support for loading this file package
[ 87%] Building CXX object Source/Tools/Urho3DPlayer/CMakeFiles/Urho3DPlayer.dir/Urho3DPlayer.cpp.o
[ 87%] Linking CXX executable …\bin\Urho3DPlayer.html
parseTools.js preprocessor error in shell.html:1: “#!/usr/bin/env firefox”!

undefined:102
throw e;
^
Unclear preprocessor command on line 0: #!/usr/bin/env firefox
(Use node --trace-uncaught ... to show where the exception was thrown)
em++: error: ‘D:/emsdk/node/14.15.5_64bit/bin/node.exe D:\emsdk\upstream\emscripten\tools/preprocessor.js C:\Users\pc\AppData\Local\Temp\emscripten_temp_0rieuf5p\settings.js shell.html’ failed (1)
Source\Tools\Urho3DPlayer\CMakeFiles\Urho3DPlayer.dir\build.make:107: recipe for target ‘bin/Urho3DPlayer.html’ failed
mingw32-make[2]: *** [bin/Urho3DPlayer.html] Error 1
CMakeFiles\Makefile2:2008: recipe for target ‘Source/Tools/Urho3DPlayer/CMakeFiles/Urho3DPlayer.dir/all’ failed
mingw32-make[1]: *** [Source/Tools/Urho3DPlayer/CMakeFiles/Urho3DPlayer.dir/all] Error 2
Makefile:164: recipe for target ‘all’ failed
mingw32-make: *** [all] Error 2

It seems you still have the old “shell” html file. Remove the shebang line as the newer Emscripten toolchain has a “#” preprocessor that doesn’t understand age-old shebang concept.

Hi,weitjong! Thanks for you reply! What EMSDK version is right for Urho3D-1.7?

Seriously you are better of with current master branch. I am not sure I could answer that question anymore from the top of my head.

Atfter remove the shebang line in shell.html file,I bulid the Urho3D successfully. But still have an error as follows.

It has been awhile for me to work with Urho3D build system. Just back from a long break. So, I am not able to give you answer for every possible build errors out there. Having said that, I can provide you with one good advise. Use the master branch to build from the source and use the same EMSDK version that currently being used by our CI/CD. See this build log from website - another automation test. · urho3d/Urho3D@78ab027 · GitHub, click on the “CMake” step to expand it to see the detail. You can of course use EMSDK with higher version than what shown there, but from the past experience EMSDK developers do not have a very good track record of keeping the backward compatibility.

Ideally, once you get a version that works for you then you can try to bump the EMSDK version up again to break the build and help us to fix the root cause and submit it as PR.

Hi, weitjong
Thanks for your help! I have already bulid the Urho3D successfully with emscripten on windows10. But I want to use the lib as shared type. How can I change the lib type to shared?

Glad to hear that. Normally you would just pass the build option URHO3D_LIB_TYPE=SHARED to the build system, however, EMCC with WASM does not really support the notion of shared lib type yet. So that build option is not available for Web platform, I believe.