How to Build MySQL on Windows/Presentation
Contents |
[edit] Introduction
- It's not hard!
- Setting up shop
- Building the server
- Running the test suite
- Debugging
[edit] It's not hard!
- It's just different.
- Portable Operating System Interface for Unix
- We do have a configure step but it's not autotools (thankfully)
- You don't have to have Visual Studio 2005 (you can build with only free tools)
- You don't have to use Cygwin (thankfully x 2)
- It's all about mindset.
- Iggy has a nice writeup of several of these issues here however we are going to focus on not using Cygwin.
[edit] Setting up Shop
- Use company VMWare image or start your own
- Bitkeeper, Bison, and CMake
- Visual Studio 2005 Express and SDK
- ActiveState Perl/Cygwin
[edit] Setting up Bitkeeper, Bison, and CMake
- Bitkeeper is compatible with XP32/XP64/Vista 32. Does not work on Vista x64
- You can use plink and pageant from Putty for ssh but it's slow
- I use ssh and scp from a cygwin install
- I use a simple sendmail clone that I wrote for sending bk commits
- Download and install Bison from here.
- Use the link named 'Complete package, except sources'
- Download and install the latest CMake from here
- During install select the option to add CMake to the path (either for all users or current user)
[edit] Visual Studio 2005 Express and SDK
- Download and install Visual C++ 2005 Express edition from here
- During setup, select the option to install MSDN 2005 Express Edition (this is the docs)
- Do not select the option to install SQL Server 2005 Express Edition (unless you want to)
- Download and install the Windows SDK 6.0 from here
- The SDK will install x32 and x64 compilers, libraries, and debuggers
- You will need to specifically included the 32 bit compilers and libraries
- Configure Visual Studio to use the newly installed SDK
- Do not follow the instructions found at here
- After Windows SDK 6.0 is installed, use the Visual Studio registration shortcut that can be found in the Windows SDK start menu group. This will launch an application that will make the Visual Studio 2005 Express changes for you.
[edit] ActiveState Perl/Cygwin
- Download the ActiveState Perl MSI installer from here.
- Let the installer add the interpreter to the system path
- If building on XP or Win2k3, you can also install Cygwin from here.
- Currently, the test suite might be a bit more stable on Cygwin
[edit] Understanding CMake
- Generates project files for many different systems from a single source
- Works with Windows, Mac, and Unix
- Sources, dependencies, and project options are specified in CMakeLists.txt files
SET(CMAKE_CXX_FLAGS_DEBUG
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/extra/yassl/include)
SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/sql/message.rc
${CMAKE_SOURCE_DIR}/sql/sql_builtin.cc
${PROJECT_SOURCE_DIR}/include/sql_state.h
PROPERTIES GENERATED 1)
[edit] Building the server
[edit] Configure the server
- Open the appropriate command prompt
- Use the Visual Studio 2005 command prompt if using VS 2005
- Use the CMD shell start menu link if using the SDK and planning to use nmake
- You can open a regular command prompt and run setenv to manually target a specific platform.
- The setenv batch file will setup an environment that matches your processor architecture.
- Clone the 5.0 or 5.1 repo using normal bk syntax
- Set the default script host to cscript by running "cscript //H:CScript"
- This only needs to be done once on your system. Technically it doesn't have to be done but by default the script execution engine will be wscript which will show all output using dialogs. By setting it to cscript, all output will be sent to the console.
- From the root of the repository, call the configure script and pass in appropriate configure settings
- It's important to run configure from the root, not from the win folder
- You can see all available options in the readme (win\README)
- As an example, you can run the following in your VS2005 command prompt:
- win\configure WITH_INNOBASE_STORAGE_ENGINE MYSQL_SERVER_SUFFIX=-pro
- Now run one of the build batch files to cause CMake to generate the project files
- Use build-vs71.bat for Visual Studio 2003
- Use build-vs8.bat for Visual Studio 2005 x32
- Use build-vs8_x64.bat for Visual Studio 2005 x64 (this one should not be used if you intend to use nmake)
- Use build-nmake.bat to generate makefiles compatible with nmake for a x32 build
- Use build-nmake_x64.bat to do a 64 bit build with nmake
- [Please see the section on understanding CMake to know why we separate the 32 and 64 bit flavors]
[edit] Build the server (Visual Studio)
- Using Visual Studio 2005, open the mysql solution file by opening the file mysql.sln found in the repository root
- Choose Build|Build solution from the menu or press F7
- Congratulations -- you've now built mysql on Windows!
[edit] Build the server (command line)
- You can build mysql on the command line using Visual Studio 2005 (not Express)
- Use devenv [solutionfile] /build [solutionconfig] from the VS 2005 command prompt
- First, set your environment correctly using setenv.cmd
- Second, configure the projects appropriately. See the section above titled Configuring the Server.
- Third, run nmake from the project root.
- That's it!
[edit] Running the test suite
- mysql-test-run is now ActiveState compatible
- This allows running the test suite on newer platforms that don't support Cygwin (Vista x64)
- This is brand new work. There may be some lingering bugs
- Running using cygwin should still work on Win XP/Win2k3 x32/x64.
[edit] Debugging
[edit] In Visual Studio 2005 (x32 or x64) and Express (x32)
- This also applies to x64 debugging if you have Visual Studio 2005
- First, start the test suite. You can hit Ctrl-C to cancel it once the tests start executing. This step creates a database that you can use for debugging.
- Now set mysqld (or whatever program you want to debug) as your startup project. This, like so many other things, can be done from the menu or from the solution explorer properties menu. Here are screenshots of both.
- Set the command line options for mysqld. Here is a screenshot of my settings.
- Choose Debug|Start debugging from the menu or just hit F5.
[edit] With the standalone debuggers
- Use windbg for GUI-based debugging
- Use cdb for console-based debugging
- Debug x32 and x64 binaries using either
- Supports advanced debugging setups including remote debugging
- Only really necessary when you need to debug over a console connection or when debugging an x64 binary and Visual Studio 2005 Standard or higher is not available.
[edit] Debugging mysqld when run as a service
- First install and start the mysqld service
- Debugging the service startup and shutdown code is challenging and isn't supported by these instructions
- Now you need to attach your debugger to the running process
- With Visual Studio, you would use the Process Attach dialog as shown (Debug|Attach to Process...)
- With WinDbg or cdb, use the command line
- Attach by process id with 'windbg -p <processID>'
- Attach by process name with 'windbg -pn <processName>'
- Or use the windbg GUI as shown
[edit] Debugging mysqld when run during a test suite run
- Review Iggy's notes from here
- May want to use an editor like Notepad2 to edit the command line
- No need to set the command line every time (unless it changes)
[edit] Common Tasks
[edit] Adding a new source file
ADD_EXECUTABLE(mysqld
../sql-common/client.c derror.cc des_key_file.cc
....
${PROJECT_SOURCE_DIR}/sql/lex_hash.h)
[edit] Changing a compiler or linker setting
- Adding a preprocessor definition
ADD_DEFINITIONS(-DMYSQL_SERVER -D_CONSOLE -DHAVE_DLOPEN)
- Targeting libraries
- This will add appropriate dependencies within Visual Studio
TARGET_LINK_LIBRARIES(mysqld
heap myisam myisammrg mysys yassl zlib debug dbug yassl
taocrypt strings vio regex wsock32 ws2_32)
- Adding project dependencies
ADD_DEPENDENCIES(mysqld GenError)
[edit] Helpful Tools and Links
- Notepad2 - open source replacement for notepad that includes features like syntax highlighting. Get it here
- Notepad++ - yet another one of those. Get it here
[edit] Notes from Windows Task Force (WTF) team members
BK Woes
If you use cygwin and bk commit complains that it cannot execute the pre-commit trigger, you need to change the first line in the trigger from "#!/bin/sh" to "#!/bin/ash" in the directory .\bitkeeper\triggers. This doesn't happen often and it was supposed to be fixed but I still run into it now and again.
Of course, there the usual problems if sendmail doesn't work. Your commit will work but to get the email sent you can either fix sendmail then redo the commit or open the commits.txt file in .\bitkeeper\tmp, copy it into a new email message and send it (that only works if you haven't done another commit of course).
Intellisense
As for intellisense, it usually craps out after 5 or 6 builds with heavy mods. I work in the replication code mostly and that touches everything (or vice-versa) so when I build a great many files have to be built. There is no outward bad thing that goes on when intellisense fails -- compilation still works, it just stops doing autocomplete (something I would loathe to do without). To fix it, you just exit VS and delete the MySQL.ncb file in the root source tree. Then restart VS and wait for it to rebuild (usually only takes about 5 minutes).
Vista
- win/configure versus win\configure and how the former silently fails on some Windows variants






