bsnes-plus icon indicating copy to clipboard operation
bsnes-plus copied to clipboard

Windows build instruction are overly vague

Open breakin opened this issue 7 years ago • 8 comments

I'm a happy bsnes-plus user but when I wanted to build it myself under windows I ran into issues. I tried to follow the instructions in readme.md to the best of my ability. I consider this to be a documentation issue!

Ok so here are the current steps:

  • Get mingw-w64 (http://mingw-w64.yaxm.org/doku.php/download)
  • Install Qt 4.8.6 (http://download.qt.io/archive/qt/) and make sure its bin directory is in your path
  • Run mingw32-make

I've obviously failed to follow them so let me tell you how I interpreted them and perhaps we can improve them so the next novice nix-under-windows will have an easier time!

For the first point I followed the link and choose the "Win Build 1.5" GUI installer. I installed everything but QT since it was QT 5 and I wanted to avoid confusion with Qt 4.8.6.

For the second step I followed the link and ended up with http://download.qt.io/archive/qt/4.8/4.8.6/qt-opensource-windows-x86-mingw482-4.8.6-1.exe from http://download.qt.io/archive/qt/4.8/4.8.6/. (This is 32-bit QT).

For the third step I opened up cmd.exe. I added mingw and QT bin directory to PATH. Then I executed mingw32-make. It failed, firstly due to "uname" not existing".

After this naive approach I tried obtaining uname etc (http://gnuwin32.sourceforge.net/packages/libiconv.htm etc). Now the build failed at a later step.

When that failed I tried installing MSYS which seems to be a bash-like environment for mingw. Here it felt less obvious how to change PATH etc since I'm mostly a windows user but I think I did it right but it still didn't compile.

Perhaps I'm trying to build 64-bit with 32-bit QT binaries or I'm using the wrong type of shell. Does it try to build 64-bit binaries by default when on a 64-bit OS?

As a closing remark I wonder if it is somehow possible to debug the windows binaries using Visual Studio following these build instructions. If not, is there some other way?

breakin avatar Jan 05 '17 07:01 breakin

To modify the PATH permanently on windows you can run sysdm.cpl ,3 and click Environment Variables. This should carry over to whatever shell you're using.

If you're using mingw targeting x64 then you're likely making a 64-bit build. The provided build of QT 4.8.6 is indeed 32-bit, so you'd have to tell gcc that you want a 32-bit build by passing -m32 to the compiler and linker, or set the compiler in nall/Makefile to mingw32-g++ (in all of them, because each top level folder has its own nall for whatever reason). Also windres is going to need these flags -O coff -F pe-i386 if you're using a 64-bit mingw because they don't have a mingw32-windres afaik. It's worth mentioning that you have to pass the following include paths to the compiler C:\Qt\4.8.6\include C:\Qt\4.8.6\include\QtCore C:\Qt\4.8.6\include\QtGui (either set an env var or add -I flags manually to each makefile). The linker will need to know where to find the qt libraries, again use env or add -L/c/Qt/4.8.6/lib to link flags. snesfilter needs openmp so make sure that's available.

How about providing a link to the same mingw32 that qt 4.8.6 recommends (mingw32 i686-posix-dwarf), in the readme? Would prevent people from having these and similar problems (incompatible exception models come to mind).

ARM9 avatar Jan 28 '17 15:01 ARM9

Thanks for taking the time! I will go back trying to build bsnes plus now again so the comments here below are very preliminary.

Seems like there are quite a few special cases here, especially for 64-bit. I would be ok to build a 32-bit binary if that is easier. I guess I should download mingw32 the instead and QT 32-etc. Do you think that would be easier?

You say "if you are using mingw". Is there an alternative?

I think what we need to specify in build instruction is:

  • What shell to use (is cmd.exe ok? msys?). You write "Run mingw32-make" but where do I do that?
  • Specify that for mingw you need this qt
  • A note on 32/64-bit (seems like 64-bit has many special cases not covered by build instructions)

A good way to measure how good build instructions are is to try to follow them on a cleanly installed computer, pretending you are stupid. Don't read anything extra into any of the instructions :)

I will have more/better suggestions here once I've managed to build it myself so I know what your suggestions actually amounts to.

ps. I have no idea where/how to run sysdm.cpl but I do know how to update environment variables using the control panel :)

breakin avatar Jan 31 '17 08:01 breakin

Seems like there are quite a few special cases here, especially for 64-bit. I would be ok to build a 32-bit binary if that is easier. I guess I should download mingw32 the instead and QT 32-etc. Do you think that would be easier?

There shouldn't be any special cases if you use the right toolchain/libraries, but I can see how the readme might be misleading. In my previous post I was explaining how to make a 32-bit build with mingw-w64. You can disregard most of it if you get the mingw32 toolchain targeting x86 (32-bit), just make sure gcc can find the qt include and lib folders and that qt\4.8.6\bin is in your path. I haven't tried building bsnes-plus 64-bit on windows yet, and correct me if I'm wrong, you'd just have to find/make a mingw 64-bit build of qt 4.8.6 (or compatible version) and use mingw targeting x64 (e.g. mingw-w64).

You say "if you are using mingw". Is there an alternative?

"If you're using mingw targeting x64" as opposed to mingw targeting x86, since I got the impression you were using the former as you installed mingw-w64 (this toolchain targets x64 by default afaik). You can't link a 64-bit application with a 32-bit library.

And just in case I misinterpreted your question, alternative toolchains would be clang/llvm and msvc++, but you won't be able to build bsnes-plus as-is with either (mostly makefile stuff, some code might be incompatible with vc++).

What shell to use (is cmd.exe ok? msys?). You write "Run mingw32-make" but where do I do that?

I used cmd.exe when I built with mingw32, shouldn't be a problem to use some other shell. Run mingw32-make in cmd.exe, in the bsnes-plus\bsnes directory. Building this project on windows certainly requires some familiarity with gnu tools and the gcc toolchain, how about adding some instructions on setting up mingw and qt on windows? It's possible that a lot of windows users are more familiar with visual studio.

ps. I have no idea where/how to run sysdm.cpl but I do know how to update environment variables using the control panel :)

Run as in win+R or just type it into cmd, that works too. It's the same as doing it via the control panel so you're fine.

Good luck!

ARM9 avatar Jan 31 '17 16:01 ARM9

I've been meaning to expand on the Windows build instructions since a few releases ago, and I'll be able to finally respond to this in more detail when I'm not busy at work, but I'll point out a few basic essentials:

  • Use mingw-w64, preferably with GCC 4.9.* (newer toolchains may work but I can't vouch for them yet) and preferably as a build that defaults to targeting x86 (mingw-w64 distributes these as "Toolchains targeting Win32"). Otherwise, if you have a dual-target version of the compiler, you'll have to edit the makefiles so that the -m32 switch is passed to the compiler. Do not use the original MinGW toolchain, for reasons that are already outlined in the readme

  • To build 64-bit bsnes-plus, the process is basically the same. 64-bit versions of Qt 4.8.6 are available at https://sourceforge.net/projects/qt64ng/files/qt/x86-64/4.8.6/. When downloading the toolchain and the Qt libraries, be sure to select SEH instead of SJLJ or you'll end up with builds of bsnes-plus that perform considerably worse than 32-bit ones.

  • As mentioned already, mingw-w64's bin directory needs to be in your PATH variable. I don't actually remember if it includes the uname command out of the box, but you don't actually need it on Windows (you may get an error message when building which can be safely ignored)

  • As long as Qt's bin directory is also in your PATH, the correct include and lib directories will be provided to the compiler/linker automatically. You can also manually specify a top-level Qt install directory at build time like mingw32-make qtpath=c:\path\to\Qt\4.8.6

devinacker avatar Jan 31 '17 16:01 devinacker

This is great. I'll come back once I've succeeded or failed to build but hopefully now I can sort it out! Will gladly help you write better build instructions once I know more! Thanks for all the help so far!

breakin avatar Jan 31 '17 19:01 breakin

No problem!

At this point I really ought to use GitHub's wiki feature to create pages with build instructions for each platform instead...

devinacker avatar Jan 31 '17 19:01 devinacker

Maybe. I do like when everything is bundled with the source though!

breakin avatar Jan 31 '17 20:01 breakin

I also think the windows build instructions need work. I'm struggling to build it here: https://forums.nesdev.org/viewtopic.php?t=23877

jeffythedragonslayer avatar Jun 23 '22 18:06 jeffythedragonslayer