Wednesday, August 11, 2010

MySQL Cluster on Windows - NDB API part 4 - Finishing it up

So we have come to the forth and last part of this small series on how to get started with NDB MGM API on Windows. I am planning some more code using NDB API specifically, but that will be a separate series.
If you haven't followed this series before, the parts before this one were:
In this part, I will show you how to build the finished application, but before that I will make a correction in the code that I showed last time. The code shown then will usually work, but I have a slightly weird development environment, as I use so many different tools. because of this, I have modified the code to compile nicely in Visual Studio 2008.

So, the file NDBMonitor.rc really should look like this:
#include "resource.h"
#include "WinUser.h"
#define IDC_STATIC (-1)

IDD_DIALOG_MAIN DIALOGEX 0, 0, 310, 194
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION |
WS_SYSMENU
CAPTION "NDB Monitor"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN DEFPUSHBUTTON "OK",IDOK,253,173,50,14
LISTBOX IDC_LIST_NODES,7,23,186,164,LBS_NOINTEGRALHEIGHT |
WS_VSCROLL | WS_TABSTOP
LTEXT "Connect string:",IDC_STATIC,7,7,55,14,SS_CENTERIMAGE
EDITTEXT IDC_EDIT_CONNECTSTRING,63,7,182,14,ES_AUTOHSCROLL
PUSHBUTTON "Connect",IDC_BUTTON_CONNECT,253,7,50,14
PUSHBUTTON "Refresh",IDC_BUTTON_REFRESH,199,173,50,14,WS_DISABLED
END
Not much, but somewhat, different than before. OK, so we are OK so far, now we will build the thing. We have prepared the MySQL Cluster libraries and includefiles and stiff like that before, but I will assume a few things going forward:
  • MySQL Cluster is installed in C:\MYSQL714b
  • Microsoft Visual Studio, and the Express version is fine for this exercise, is located in C:\Program, Files\Microsoft Visual Studio 9.0
  • Microsoft Windows SDK is installed at C:\Program Files\Microsoft SDK2\Windows\v7.0a (This is part of Visual Studio 2008)
If you have different locations for your stuff, then some modifications are necessary, or course. I will not use the Visual Studio IDE for building this, showing and explaining how to set thet up would take up too much time, rather, I use a Makefile. So, in the directory where you placed the other source files we products, create a file called Makefile (with no extension, not even .txt. Watch out if you use Notepad!) with this contents:
MYSQL_HOME=C:\MySQL714b

VSHOME=C:\Program Files\Microsoft Visual Studio 9.0
SDKHOME=C:\Program Files\Microsoft SDKs\Windows\v7.0A
CC="$(VSHOME)\VC\bin\cl"
RC="$(SDKHOME)\bin\rc"


RCINCLUDE=/i "$(SDKHOME)\include" /i "$(VSHOME)\VC\include"
CFLAGS=/TP /MT /D "WIN32" /D "_WINDOWS" /I "$(SDKHOME)\Include" \
/I "$(VSHOME)\VC\Include" /I "$(MYSQL_HOME)\include" \
/I "$(MYSQL_HOME)\include\storage\ndb"



LDFLAGS=/LIBPATH:"$(SDKHOME)\lib" /LIBPATH:"$(VSHOME)\VC\lib" \
/LIBPATH:"$(MYSQL_HOME)\lib" \
/LIBPATH:"$(MYSQL_HOME)\lib\opt" /MACHINE:X86 ndbapi.lib \
ndbmgmapi.lib mysys.lib ndbclient.lib ndblogger.lib \
wsock32.lib strings.lib kernel32.lib user32.lib gdi32.lib \
winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib \
oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
NDBMonitor.exe: NDBMonitor.c NDBMonitor.res
$(CC) $(CFLAGS) NDBMonitor.c /link $(LDFLAGS) NDBMonitor.res
NBDMonitor.res: NDBMonitor.rc
$(RC) $(RCINCLUDE) /fo NDBMonitor.res NDBMonitor.rc

Now we are nearly ready to begin building our application, if you installed Visual Studio 2008 the usual way, then you can start a command prompt with the appropriate environment by using the Start->Programs->Microsoft Visual C++ 2008 Express Edition->Visual Studio Tools->Visual Studio 2008 Command Prompt. Alternatively, make sure that you have the following directories in your path in a DOS Window:
  • C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE
  • C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN
  • C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin
Now, from this DOS Windows, enter the command nmake and assuming you have no errors, you have an NDBMonitor.exe executable in th at directory. Run if from the commandline and you will get a Window that looks like this:
Not very exciting, I know, but if you type in the connect string to a MySQL Cluster management node, like localhost:1186 in the Connect string edit box and click Connect, then you will see the status of that Cluster in a simple way, like this:
Click the Refresh button to refresh the status shown in the listbox. So that's it for now. Happy Clustering folks!

/Karlsson

3 comments:

Flex said...

This blog really is doing great for me. This blog also offers me more ideas and knowledge. Thanks!
----------------------

performance testing

Karlsson said...

Thank you!

Sara said...

Very clear and precise.
drivers hp