| 1 | = Building BOINC applications on Windows = |
| 2 | |
| 3 | == Microsoft Visual Studio == #vs |
| 4 | |
| 5 | There is a free version, [http://msdn2.microsoft.com/en-us/express/aa975050.aspx Visual C++ 2008 Express Edition], |
| 6 | which works with the BOINC project file (after it is converted). |
| 7 | You'll also need the [http://www.microsoft.com/downloads/details.aspx?FamilyId=A55B6B43-E24F-4EA3-A93E-40C0EC4F68E5&displaylang=en Microsoft Platform SDK] |
| 8 | and some [http://msdn.microsoft.com/en-us/vstudio/aa700755.aspx changes to your Visual Studio Express] |
| 9 | installation to include the SDK. |
| 10 | Warning: you cannot use more recent versions of the SDK (which do not include glaux). |
| 11 | |
| 12 | If you use your own project file: |
| 13 | |
| 14 | * If your application uses graphics, go to Properties -> Linker -> Input. In Delay Loaded DLLs add |
| 15 | {{{ |
| 16 | GDI32.DLL;OPENGL32.DLL;GLU32.DLL |
| 17 | }}} |
| 18 | and in Additional Dependencies add |
| 19 | {{{ |
| 20 | delayimp.lib |
| 21 | }}} |
| 22 | * Configure your project to use ANSI strings rather than Unicode. |
| 23 | |
| 24 | === Microsoft Specific Changes === |
| 25 | |
| 26 | Recent versions of Visual Studio include changes to the C Runtime Library which throw up this error when an invalid parameter is passed to various functions: |
| 27 | |
| 28 | [[Image(runtimerror.png)]] |
| 29 | |
| 30 | To prevent this dialog from being displayed and presenting a bad user experience on the BOINC platform, please add this to your applications initialization: |
| 31 | {{{ |
| 32 | #if defined(_MSC_VER) && (_MSC_VER >= 1400) |
| 33 | _set_invalid_parameter_handler(AppInvalidParameterHandler); |
| 34 | #endif |
| 35 | }}} |
| 36 | |
| 37 | Where AppInvalidParameterHandler() is defined as: |
| 38 | {{{ |
| 39 | #if defined(_MSC_VER) && (_MSC_VER >= 1400) |
| 40 | void AppInvalidParameterHandler(const wchar_t* expression, const wchar_t* function, const wchar_t* file, unsigned int line, uintptr_t pReserved ) { |
| 41 | DebugBreak(); |
| 42 | } |
| 43 | #endif |
| 44 | }}} |
| 45 | |
| 46 | |
| 47 | == MinGW and Dev-C++ == #devcpp |
| 48 | |
| 49 | If you can't or don't want to use Visual Studio to build applications, |
| 50 | the easiest alternative is |
| 51 | [http://www.bloodshed.net/devcpp.html Dev-C++], an open-source development environment based on the GCC compilers. |
| 52 | Use the MinGW compile option. |
| 53 | |
| 54 | SETI@home uses Dev-C++ for its Windows build; |
| 55 | you can get the project file |
| 56 | [https://setisvn.ssl.berkeley.edu/trac/browser/seti_boinc/client/win_build/seti_boinc.dev here]. |
| 57 | |
| 58 | == MinGW command-line == #mingw-cli |
| 59 | |
| 60 | To build the BOINC library and API for Windows using [http://www.mingw.org/ MinGW] (on MSYS, Cygwin or cross-platform) compile with "make -f Makefile.mingw" while in the "lib" folder. |
| 61 | |
| 62 | Per default the targets ''libboinc_api.a'' ''libboinc.a'' and ''libboinc_graphics2.a'' are built. |
| 63 | Optional targets are ''libboinc_zip.a'' (requires the boinc_zip tree), |
| 64 | and the usual ''clean'', ''install'' and ''uninstall'' targets. |
| 65 | |
| 66 | The following environment variables influence the build: |
| 67 | * CC and CXX : set to MinGW C and C++ compiler |
| 68 | * AR and RANLIB : set to ''ar'' and ''ranlib'' of the ''target'' system when cross-compiling |
| 69 | * BOINC_SRC : set to the root of the boinc source tree, defaults to .. (i.e. 'make -f Makefile.mingw' should work within lib/) |
| 70 | * BOINC_PREFIX : set to destination if you want to use ''install'' and ''uninstall'' targets; defaults to /usr/local/boinc |
| 71 | * NOCYGWIN : set to '-mno-cygwin' if you are building on Cygwin but for use on plain Windows (i.e. w/o cygwin.dll) |
| 72 | |
| 73 | == Cygwin == #cygwin |
| 74 | |
| 75 | [http://www.cygwin.com/ Cygwin] may be another alternative for building Windows apps. |
| 76 | There are several issues: |
| 77 | |
| 78 | * If you build the API library directly, it will use use shared memory |
| 79 | to communicate with the BOINC client. |
| 80 | This won't work if you use the standard Windows client, |
| 81 | which uses memory-mapped files rather than shared memory. |
| 82 | * In order to run a cygwin application from BOINC, |
| 83 | you need to supply all the cygwin DLLs that the application requires |
| 84 | in addition to the executable. |
| 85 | You can get LISTDLLS from http://www.sysinternals.com/. |
| 86 | It will tell you what DLLs a running executable has loaded. |
| 87 | * Cygwin is GPL software. |
| 88 | If you link to the cygwin DLL, |
| 89 | then either your application has to be GPL as well, |
| 90 | or you will have to buy a commercial license from Red Hat. |
| 91 | |
| 92 | However, it can be done. |
| 93 | Check the [https://twiki.cern.ch/twiki/bin/view/LHCAtHome/BoincPort cookbook from CERN] |
| 94 | (search for "Instructions to Port the application to Windows"). |
| 95 | |
| 96 | == Symbol Stores == #symbol-stores |
| 97 | |
| 98 | To obtain useful stack traces in the event of an application crash, symbols are needed. |
| 99 | Normally symbols are "stripped" from executables. |
| 100 | Without symbols, callstacks are just a list of memory addresses. |
| 101 | You then must load the un-stripped executable in memory using the |
| 102 | same operating system and similar processor to jump to that memory address in order |
| 103 | to determine the function name and parameters. |
| 104 | This is very labor intensive. |
| 105 | |
| 106 | Microsoft created a technology called a 'Symbol Store' which allows Windows debuggers |
| 107 | to locate and download compressed symbol files to diagnose problems |
| 108 | and convert function pointers into human readable text. |
| 109 | This greatly speeds up the process of diagnosing and fixing bugs. |
| 110 | |
| 111 | With the BOINC Runtime Debugger for Windows framework a project can publish their |
| 112 | symbol files and only have to distribute the application to each of the BOINC clients. |
| 113 | When a crash event occurs the runtime framework will download the symbol |
| 114 | file from the symbol store and then proceed to dump as much diagnostic information |
| 115 | as possible to help projects diagnose the failure. |
| 116 | |
| 117 | === Requirements === |
| 118 | You'll need the latest stable release of the [http://www.microsoft.com/whdc/devtools/debugging/default.mspx Debugging Tools for Windows. ] |
| 119 | |
| 120 | Verify that your executable is setup to generate PDB debugging symbols for a release build. |
| 121 | |
| 122 | Verify that the advance linker option to generate a checksum is enabled for a release build. |
| 123 | |
| 124 | You'll need to explicitly name both your EXE and PDB before compilation since the debugger bases the name of the PDB file off of information that is stored in the executable header. |
| 125 | |
| 126 | ==== Project Symbol Store ==== |
| 127 | |
| 128 | Add a symstore element to your config.xml file for the project: |
| 129 | |
| 130 | {{{ |
| 131 | <boinc> |
| 132 | <config> |
| 133 | <symstore>http://sample.example.com/symstore</symstore> |
| 134 | </config> |
| 135 | </boinc> |
| 136 | }}} |
| 137 | |
| 138 | === Adding symbols to the symbol store === |
| 139 | [http://msdn.microsoft.com/en-us/library/cc266480.aspx Symstore] is a utility to manage symbol stores. You'll want to create a local symbol store on your Windows build machine in which you'll initially add new symbol files with each revision of your application. |
| 140 | |
| 141 | Symstore will compress the symbol file and then copy it into your local symbol store. |
| 142 | |
| 143 | Below is an example command which you can run from the Windows command line or cygwin command line. |
| 144 | |
| 145 | {{{ |
| 146 | symstore.exe add /l /f c:\SampleSrc\*.pdb /s c:\symstore /compress /t "Sample" /v "5.02" /o /c "Application Release" |
| 147 | }}} |
| 148 | |
| 149 | === Uploading symbols to the symbol store === |
| 150 | |
| 151 | Most projects tend to use scp to copy files between Windows machines and their project server. |
| 152 | |
| 153 | The example below copies the entire symstore to the target location. After the copy operation you can delete all the subdirectories except '000Admin' to save time uploading for future application symbols. |
| 154 | |
| 155 | {{{ |
| 156 | pscp.exe -r -C -batch c:\symstore sample@project.example.com:projects/sample/html/user/symstore |
| 157 | }}} |
| 158 | |