Resolving the bison.exe m4 Invalid argument Error when building MySQL/MariaDB/XtraDB on Windows

If you’ve tried compiling MySQL/MariaDB/XtraDB from source code on Windows, you may have run into the following error:

C:\GnuWin32\bin\bison.exe: m4: Invalid argument

Now, it is a known bug to receive this error if you install it to a location with spaces in the path. So don’t do that!

But, there are cases when you have not installed it to a path with spaces, and you still receive this error.

I’ve encountered it a number of times, and I’m not the only one (btw, thanks Venu for your existing work-around up to this point!).


Compile MySQL/MariaDB/XtraDB on Windows and receive the following error during compilation:

C:\GnuWin32\bin\bison.exe: m4: Invalid argument


As you can see, there is no space in the path that is even reported.

Let’s double-check that that is the path returned from the command line:

C:\mariadb-5.3\bld>where bison

C:\mariadb-5.3\bld>where m4

Again, both are stored in a location without spaces.

Let’s double-check what CMake reports for the bison path in CMakeCache.txt:

//path to the bison executable

Again, the same path with no spaces.

In the build output (either from Visual Studio or the Command Line), near the “bison.exe: m4: Invalid argument” error, you should see a link to the “build log” for that which failed, which contains additional information.

Opening that file, you’ll see this is the full command that is trying to be run:

C:\GnuWin32\bin\bison.exe -y -p MYSQL --output=C:/mariadb-5.3/bld/sql/ 
--defines=C:/mariadb-5.3/bld/sql/sql_yacc.h C:/mariadb-5.3/sql/sql_yacc.yy

I recommend trying to run it from the command line yourself.

If you’re already seeing the “bison.exe: m4: Invalid argument” error, then you’re likely going to see it here (which is good for later testing):

C:\mariadb-5.3\bld>C:\GnuWin32\bin\bison.exe -y -p MYSQL 
--defines=C:/mariadb-5.3/bld/sql/sql_yacc.h C:/mariadb-5.3/sql/sql_yacc.yy
C:\GnuWin32\bin\bison.exe: m4: Invalid argument

So what is going on?

Well, thanks to Wlad(!), he recommended I run Procmon to see what it reports.

  1. I downloaded and ran procmon.exe.
  2. Run bison command from command line:
    C:\GnuWin32\bin\bison.exe -y -p MYSQL 
    --defines=C:/mariadb-5.3/bld/sql/sql_yacc.h C:/mariadb-5.3/sql/sql_yacc.yy
  3. In procmon, search (ctrl + f) for “bison”
  4. Locate an entry (may see many) and look at the paths for the bison.exe executable (it is easy output to read).

The $Path for the bison entry said:

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\GnuWin32\Bison

Aha! For one, that is just a directory with no executables. But for two, and more importantly, it has a “space” in the path.

So, that is the root cause of the problem.


Initially, I had run an installer to install GnuWin32 Bison. This added docs shortcuts to the C:\ProgramData\Microsoft\Windows\Start Menu\Programs\GnuWin32\Bison location (and apparently created some registry entry that ultimately was used by VS2008), and links to those docs in my Start Menu.

Personally, I know where the docs are, so I can live without them being in my “Start Menu” (heck, maybe you could even copy them back, but it ultimately needs removed from the registry).

So, if you’re the same way, then this should work for you:

  1. Copy C:\GnuWin32 (and subdirs) to a safe location
  2. Run the bison uninstall (to remove the entry from the registry)
  3. Ensure current C:\GnuWin32 does not exist
  4. Ensure C:\ProgramData\Microsoft\Windows\Start Menu\Programs\GnuWin32 does not exist (those true docs will already be saved in the copy we made anyway, that will be restored to C:\GnuWin32)
  5. Re-boot computer (because stale registry values will remain and thus a restart is necessary – this I also detected with Procmon)
  6. Copy the saved GnuWin32 (and subdirs) back to C:\.
  7. Ensure C:\GnuWin32\bin is in the $PATH for Windows.

Now, re-run your command from the command line (or rebuild – but the command line command is much quicker for testing):

C:\mariadb-5.3\bld>C:\GnuWin32\bin\bison.exe -y -p MYSQL --output=C:/mariadb-5.3/bld/sql/ 
--defines=C:/mariadb-5.3/bld/sql/sql_yacc.h C:/mariadb-5.3/sql/sql_yacc.yy



Once that’s good to go, you’ll know your build will run successfully too (at least it won’t fail with this dreaded m4 error.)


Related Build Links:

Hope this helps.

How to Build MySQL 5.5 from Source Code on Windows

Not counting obtaining the source code, and once you have the prerequisites satisfied, [Windows] users can build from source code in 5 easy steps.

Prerequisites – Install & ensure they are in the $PATH:

  1. CMake <-- Download
  2. C++ compiler <-- Visual Studio 2008 Express - Free Download
  3. Bison <-- Download (ensure m4.exe is also included, which it should be)

Optional (but most likely you’ll want):

  1. Perl <-- For Test Suite/Scripts. Strawberry Perl is a great option.
  2. Bazaar <-- If want latest source tree

Tip: Install these in locations where spaces are not in the path. Specifically, watch for the Bison/m4 as there is a known bug with regards to that.


Now that that’s out of the way, we can begin. You just need to decide if you want to build from source code you download or from the latest development tree.

This will walk through building from the latest development tree (since the downloaded version requires no extra steps – just grab it from any mirror).

Also, this post assumes you can connect to the Launchpad repository via Bazaar and download the source (i.e., you’ll have to create SSH keys to connect to Launchpad – see this write-up for more details. You might also need Pageant too, if you don’t already have it.)

I. Prerequisite Checks:

C:\>cmake --version
cmake version 2.6-patch 4

C:\>bison --version
bison (GNU Bison) 2.4.1

C:\>m4 --version
m4 (GNU M4) 1.4.13

C:\>perl --version
This is perl 5, version 12, subversion 3

C:\>bzr --version
Bazaar (bzr) 2.4.1


II. Obtain Source Code (skip this if you download the source directly from a mirror):

  1. Open Pageant -> Add Key -> Select your SSH Key (for Launchpad)
  2. cd C:\
  3. bzr init-repo –trees mysql-5.5
  4. cd mysql-5.5
  5. bzr branch lp:mysql-server/5.5 mysql-5.5


III. Build/Compile Source Code:

  1. cd mysql-5.5
  2. cmake . -DBUILD_CONFIG=mysql_release -G “Visual Studio 9 2008”
  3. Copy m4.exe to $basedir/sql <-- this avoids any m4.exe errors (or fix this permanently if this affects you)
  4. Open Solution in VS: File -> Open -> Project/Solution -> C:\mysql-5.5\mysql-5.5\MySQL.sln
  5. Now build in VS: Build -> Build Solution (or F7)
========== Build: 93 succeeded, 0 failed, 5 up-to-date, 10 skipped ==========

There you have it! (Assuming you have “0 failed”, otherwise, you’ve got some debugging to do.)


For those interested, I have full outputs, and common errors (with their solutions) from the entire process here:

MySQL 5.5 Windows Build Appendix : Full Outputs and Common Errors from Building MySQL 5.5 on Windows


Build Notes (step #2 above):

The -DBUILD_CONFIG=mysql_release flag uses the same build options used for official releases, which are stored in cmake/build_configurations/mysql_release.cmake.

The simplest you could use is: cmake . -G “Visual Studio 9 2008”

Or you could specify a number of options: cmake . -DMYSQL_SERVER_SUFFIX=-chris -DWITHOUT_FEDERATED_STORAGE_ENGINE=1 -DWITHOUT_BLACKHOLE_STORAGE_ENGINE=1 -G “Visual Studio 9 2008”

The -G lets know which compiler will be used. In this case, I’m using VS 2008 Express. If you were using VS 2005, it’d be “Visual Studio 8 2005”, but I’m not sure if VS 2005 will even work.

This command should end with something like “– Build files have been written to: C:/…” or you’ll need to debug.

Lastly, the cmake command creates the MySQL.sln file and all .vcproj files.


IV. Kicking the tires …

Creating a “package” in Visual Studio is quite simple:

In the “Solution Explorer” view (far right-hand side of page), right-click on “PACKAGE” -> then “Build”.

If you have problems with this, it can be pieced together easily enough:

  1. Make main dir mysql-5.5.xx
  2. Make subdir bin/ – copy in all .exe files (from client/debug, sql/debug, */debug, etc.)*
  3. Make subdir data/ – copy from sql/data/
  4. Make subdir scripts/ – copy from scripts/ (at least all perl, sql, and sh scripts)
  5. Make subdir share/ – copy from sql/share/
  6. Create my.ini

* Notes re: .exe files: mysqld.exe is located in /sql/debug/ and mysql.exe is located in /client/debug/. The remaining .exe files are located in /client/debug/, /sql/debug/, /extra/debug/, /libmysql/debug/, /mysys/debug/, /scripts/debug/, /storage/myisam/debug/, /storage/heap/debug/, and /tests/debug/.

Now start mysqld:

mysql> select version();
| version()        |
| 5.5.21-debug-log |

Of course you should test it a bit more than that, but I’ll leave that to you.