/ windows-build.txt
windows-build.txt
  1  ######################################################################################
  2  #                                                                                    #
  3  #          Native WIN32 setup and build instructions (on mingw32/Windows):           #
  4  #                                                                                    #
  5  ######################################################################################
  6  
  7  (See bottom of file for steps to cross-build for Win32 from Linux.)
  8  
  9  **************************************************************************************
 10  * Introduction                                                                       *
 11  **************************************************************************************
 12  The following instructions have been tested on both Windows 7 and Windows XP.
 13  Most of what is described below (copying files, downloading files, etc.) can be done
 14  directly in the MinGW MSYS shell; these instructions do not do so because package
 15  versions and links change over time. The best way is to use your browser, go to the
 16  links directly, and see for yourself which versions you want to install.
 17  Winrar was used to do the extracting of archive files in the making of this guide.
 18  
 19  If you think that this documentation was helpful and you wish to donate, you can
 20  do so at the following address. 12KaKtrK52iQjPdtsJq7fJ7smC32tXWbWr
 21  
 22  **************************************************************************************
 23  * A tip that might help you along the way                                            *
 24  **************************************************************************************
 25  Enable "QuickEdit Mode" in your Command Prompt Window or MinGW Command Prompt
 26  Window (No need to go into the context menu to choose edit-mark/copy/paste):
 27  Right-click on the title bar and click Properties. Under the Options tab, check
 28  the box for "QuickEdit Mode". Alternately, if you want this change to be
 29  permanent on all of your Command Prompt Windows; you can click Defaults instead
 30  of Properties as described above. Now you can drag and select text you want to
 31  copy, right-click to copy the text to the clipboard and right-click once again to
 32  paste it at the desired location. You could for example, copy some text from this
 33  document to the clipboard and right click in your Command Prompt Window to paste
 34  what you copied.
 35  
 36  **************************************************************************************
 37  * Install mingw32                                                                    *
 38  **************************************************************************************
 39  Go to this url ==> http://www.mingw.org/wiki/Getting_Started
 40  Click the link that says "Download and run the latest mingw-get-inst version."
 41  Download and run the latest file. Install MinGW in the default directory.
 42  (I downloaded the one labeled "mingw-get-inst-20120426" - note that this could
 43  be a different version later.)
 44  Make sure to check the option for "Download latest repository catalogs".
 45  I just selected all the check boxes (excluding "Fortran Compiler") so that everything
 46  was installed.
 47  
 48  **************************************************************************************
 49  * Run the MSYS shell for the first time to create your user directory                *
 50  **************************************************************************************
 51  (Start Icon/keyboard key ==> All Programs ==> MinGW ==> MinGW Shell).
 52  This will create your user directory for you.
 53  
 54  **************************************************************************************
 55  * Install libpdcurses                                                                *
 56  **************************************************************************************
 57  Type the lines below to install libpdcurses.
 58  mingw-get install mingw32-libpdcurses
 59  mingw-get install mingw32-pdcurses
 60  Ctrl-D or typing "logout" and pressing the enter key should get you out of the
 61  window.
 62  
 63  **************************************************************************************
 64  * Copy CGMiner source to your MSYS working directory                                 *
 65  **************************************************************************************
 66  Copy CGMiner source code directory into:
 67  \MinGW\msys\1.0\home\(folder with your user name)
 68  
 69  **************************************************************************************
 70  * Install AMD APP SDK, latest version (only if you want GPU mining)                  *
 71  **************************************************************************************
 72  Note: You do not need to install the AMD APP SDK if you are only using Nvidia GPU's
 73  Go to this url for the latest AMD APP SDK:
 74   http://developer.amd.com/tools/heterogeneous-computing/amd-accelerated-parallel-processing-app-sdk/downloads/
 75  Go to this url for legacy AMD APP SDK's:
 76   http://developer.amd.com/tools/heterogeneous-computing/amd-accelerated-parallel-processing-app-sdk/downloads/download-archive/
 77  Download and install whichever version you like best.
 78  Copy the folders in \Program Files (x86)\AMD APP\include to \MinGW\include
 79  Copy \Program Files (x86)\AMD APP\lib\x86\libOpenCL.a to \MinGW\lib
 80  Note: If you are on a 32 bit version of windows "Program Files (x86)" will be
 81  "Program Files".
 82  Note2: If you update your APP SDK later you might want to recopy the above files
 83  
 84  **************************************************************************************
 85  * Install AMD ADL SDK, latest version (only if you want GPU monitoring)              *
 86  **************************************************************************************
 87  Note: You do not need to install the AMD ADL SDK if you are only using Nvidia GPU's
 88  Go to this url ==> http://developer.amd.com/tools/graphics-development/display-library-adl-sdk/
 89  Download and unzip the file you downloaded.
 90  Pull adl_defines.h, adl_sdk.h, and adl_structures.h out of the include folder
 91  Put those files into the ADL_SDK folder in your source tree as shown below.
 92  \MinGW\msys\1.0\home\(folder with your user name)\cgminer-x.x.x\ADL_SDK
 93  
 94  **************************************************************************************
 95  * Install GTK-WIN, required for Pkg-config in the next step                          *
 96  **************************************************************************************
 97  Go to this url ==> http://sourceforge.net/projects/gtk-win/
 98  Download the file.
 99  After you have downloaded the file Double click/run it and this will install GTK+
100  I chose all the selection boxes when I installed.
101  Copy libglib-2.0-0.dll and intl.dll from \Program Files (x86)\gtk2-runtime\bin to
102  \MinGW\bin
103  Note: If you are on a 32 bit version of windows "Program Files (x86)" will be
104  "Program Files".
105  
106  **************************************************************************************
107  * Install pkg-config                                                                 *
108  **************************************************************************************
109  Go to this url ==> http://www.gtk.org/download/win32.php
110  Scroll down to where it shows pkg-cfg.
111  Download the file from the tool link. Extract "pkg-config.exe" from bin and place in
112  your  \MinGW\bin directory.
113  Download the file from the "Dev" link. Extract "pkg.m4" from share\aclocal and place
114  in your \MingW\share\aclocal directory.
115  
116  **************************************************************************************
117  * Install libcurl                                                                    *
118  **************************************************************************************
119  Go to this url ==> http://curl.haxx.se/download.html#Win32
120  At the section where it says "Win32 - Generic", Click on the link that indicates
121  Win32 2000.XP 7.27.0 libcurl SSL and download it.
122  The one I downloaded may not be current for you. Choose the latest.
123  Extract the files that are in the zip (bin, include, and lib) to their respective
124  locations in MinGW (\MinGW\bin, \MinGW\include, and \MinGW\lib).
125  Edit the file \MinGW\lib\pkgconfig\libcurl.pc and change "-lcurl" to
126  "-lcurl -lcurldll".
127  Ref. http://old.nabble.com/gcc-working-with-libcurl-td20506927.html
128  
129  **************************************************************************************
130  * Build cgminer.exe                                                                  *
131  **************************************************************************************
132  Run the MinGW MSYS shell
133  (Start Icon/keyboard key ==> All Programs ==> MinGW ==> MinGW Shell).
134  Change the working directory to your CGMiner project folder.
135  Example: cd cgminer-2.1.2 [Enter Key] if you are unsure then type "ls -la"
136  Another way is to type "cd cg" and then press the tab key; It will auto fill.
137  Type the lines below one at a time. Look for problems after each one before going on
138  to the next.
139  
140        adl.sh (optional - see below)
141        autoreconf -fvi
142        CFLAGS="-O2 -msse2" ./configure (additional config options, see below)
143        make
144        strip cgminer.exe  <== only do this if you are not compiling for debugging
145  
146  **************************************************************************************
147  * Copy files to a build directory/folder                                             *
148  **************************************************************************************
149  Make a directory and copy the following files into it. This will be your CGMiner
150  Folder that you use for mining. Remember the .cl filenames could change on later
151  releases. If you installed a different version of libcurl then some of those dll's
152  may be different as well.
153    cgminer.exe     from \MinGW\msys\1.0\home\(username)\cgminer-x.x.x
154    *.cl            from \MinGW\msys\1.0\home\(username)\cgminer-x.x.x
155    README          from \MinGW\msys\1.0\home\(username)\cgminer-x.x.x
156    libcurl.dll     from \MinGW\bin
157    libidn-11.dll   from \MinGW\bin
158    libeay32.dll    from \MinGW\bin
159    ssleay32.dll    from \MinGW\bin
160    libpdcurses.dll from \MinGW\bin
161    pthreadGC2.dll  from \MinGW\bin
162  
163  **************************************************************************************
164  * Optional - Install Git into MinGW/MSYS                                             *
165  **************************************************************************************
166  Go to this url ==> http://code.google.com/p/msysgit/
167  Click on the Downloads tab.
168  Download the latest "Portable" git archive.
169  Extract the git*.exe files from the bin folder and put them into \MinGW\bin.
170  Extract the share\git-core folder and place it into \MinGW\share.
171  After the previous step you should have a folder called \MinGW\share\git-core.
172  To test if it is working, open a MinGW shell and type the following:
173    git config -–global core.autocrlf false (note: one time run only)
174    git clone git://github.com/ckolivas/cgminer.git
175  
176  If you simply just want to update the source after you have already cloned, type:
177    git pull
178  "git pull" did not work for me. Try the following which does the same thing:
179    git fetch && git merge FETCH_HEAD
180  
181  Now you can get the latest source directly from github.
182  
183  **************************************************************************************
184  * Optional - Make a .sh file to automate copying over ADL files                      *
185  **************************************************************************************
186  Make a folder/directory in your home folder and name it ADL_SDK.
187   (ref:  \MinGW\msys\1.0\home\(folder with your user name)\ADL_SDK)
188  Copy the ADL .h files into that folder/directory.
189  Open your favorite text editor and type the following into it.
190   cp -av ../ADL_SDK/*.h ADL_SDK
191  Save the file as "adl.sh" and then place the file into "\MinGW\msys\1.0\bin".
192  From now on when your current working directory is the cgminer source directory
193  You can simply type "adl.sh" and it will place the ADL header files into place
194  For you. Make sure you never remove the ADL_SDK folder from your home folder.
195  
196  **************************************************************************************
197  * Optional - Install libusb if you need auto USB device detection; required for Ztex *
198  **************************************************************************************
199  Go to this url ==> http://git.libusb.org/?p=libusb.git;a=snapshot;h=master;sf=zip
200  save the file to your local storage. Open the file and copy the libusb* folder to
201  \MinGW\msys\1.0\home\(your user directory/folder).
202  Or if you do not want to download the file directly and would like to use git then
203  Type the following from the MSYS shell in your home folder.
204  git clone git://git.libusb.org/libusb.git
205  
206  Run the MinGW MSYS shell
207  (Start Icon/keyboard key ==> All Programs ==> MinGW ==> MinGW Shell).
208  Change the working directory to your libusb project folder.
209  Example: cd libusb-something [Enter Key] if you are unsure then type "ls -la"
210  Another way is to type "cd libusb" and then press the tab key; It will auto fill.
211  Type the lines below one at a time. Look for problems after each one before going on
212  to the next.
213  
214  ./autogen.sh --disable-debug-log --prefix=/MinGW
215  make
216  make install
217  
218  You may now exit the MSYS shell.
219  Ctrl-D or typing "logout" and pressing the enter key should get you out of the
220  window.
221  
222  You will have to copy "libusb-1.0.dll" to your working cgminer binary directory.
223  You will find "libusb-1.0.dll" in the \MinGW\bin directory/folder.
224  
225  Use this method if libusb does not work for you on Ztex. Once someone lets us know
226  Libusb works instead of libusbx then we will remove the section below this line.
227  Run the MSYS shell and change into the libusb folder as above.
228  Type ==> make uninstall
229  Go to this url ==> http://libusbx.org/
230  Click on the "Downloads" tab.
231  Click on "releases".
232  Click on the latest version. I downloaded 1.0.14; yours may be newer.
233  Do not download from the link that says "Looking for the latest version?".
234  Click on "Windows"
235  Click on the file and download it. I downloaded libusbx-1.0.12-win.7z.
236  Extract the the following from the file and place in where directed.
237  Copy libusb.h from include\libusbx-1.0 to \MinGW\include\libusb-1.0\libusb.h
238  Copy contents of MinGW32\static \MinGW\lib
239  Copy contents of MinGW32\dll to \MinGW\lib
240  You will have to copy "libusb-1.0.dll" to your working cgminer binary directory.
241  
242  **************************************************************************************
243  * Some ./configure options                                                           *
244  **************************************************************************************
245  --enable-cpumining      Build with cpu mining support(default disabled)
246  --disable-opencl        Override detection and disable building with opencl
247  --disable-adl           Override detection and disable building with adl
248  --enable-bitforce       Compile support for BitForce FPGAs(default disabled)
249  --enable-icarus         Compile support for Icarus Board(default disabled)
250  --enable-modminer       Compile support for ModMiner FPGAs(default disabled)
251  --enable-ztex           Compile support for Ztex Board(default disabled)
252  --enable-scrypt         Compile support for scrypt litecoin mining (default disabled)
253  --without-curses        Compile support for curses TUI (default enabled)
254  --without-libudev       Autodetect FPGAs using libudev (default enabled)
255  
256  
257  
258  ######################################################################################
259  #                                                                                    #
260  #       Cross-compiling for Windows from Linux                                       #
261  #                                                                                    #
262  ######################################################################################
263  
264  It is possible to cross-compile Windows binaries from Linux. The
265  process is a bit different to the native steps shown above (it is also
266  possible to use wine and the native steps, but this is more messing
267  around, very slow, and not advisable.)
268  
269  ** Install mingw cross compiler
270  
271  On Ubuntu/Debian:
272  
273  sudo apt-get install mingw32
274  
275  ** create a directory to hold our cross-library dependencies
276  
277  We'll create a directory outside the source tree to hold non-system
278  libraries we depend on. We could put these in
279  /usr/i586-mingw32msvc/lib or anywhere else, instead (though keeping it
280  outside /usr means we can set it up without root privileges.)
281  
282  IMPORTANT: If you put this directory inside your cgminer directory,
283  remember 'make distclean' may delete it!
284  
285  mkdir -p ../cgminer-win32-deps/lib
286  cd ../cgminer-win32-deps
287  mkdir include
288  mkdir bin
289  
290  NB: All following steps assume you are in the "cgminer-win32-deps" directory. Adjust as necessary.
291  
292  ** pdcurses
293  
294  wget http://internode.dl.sourceforge.net/project/pdcurses/pdcurses/3.4/pdc34dllw.zip
295  unzip /home/gus/Downloads/pdc34dllw.zip
296  mv *.h include/
297  mv pdcurses.lib lib/
298  mv pdcurses.dll bin/
299  
300  ** pthreads-w32
301  
302  (NB: I found pthreads-w32 2.9.1 doesn't seem to work properly, transfers time out early due to sem_timedwait exiting immediately(?))
303  
304  wget -O lib/libpthread.a ftp://sourceware.org/pub/pthreads-win32/prebuilt-dll-2-8-0-release/lib/libpthreadGC2.a
305  wget -O include/pthread.h ftp://sourceware.org/pub/pthreads-win32/prebuilt-dll-2-8-0-release/include/pthread.h
306  wget -O include/sched.h ftp://sourceware.org/pub/pthreads-win32/prebuilt-dll-2-8-0-release/include/sched.h
307  wget -O include/semaphore.h ftp://sourceware.org/pub/pthreads-win32/prebuilt-dll-2-8-0-release/include/semaphore.h
308  wget -O lib/libpthread.a ftp://sourceware.org/pub/pthreads-win32/prebuilt-dll-2-8-0-release/lib/libpthreadGC2.a
309  wget -O bin/pthreadGC2.dll ftp://sourceware.org/pub/pthreads-win32/prebuilt-dll-2-8-0-release/lib/pthreadGC2.dll
310  
311  ** libcurl
312  
313  wget http://curl.haxx.se/gknw.net/7.33.0/dist-w32/curl-7.33.0-devel-mingw32.zip
314  unzip curl-7.33.0-devel-mingw32.zip
315  mv curl-7.33.0-devel-mingw32/include/* include/
316  mv curl-7.33.0-devel-mingw32/lib/* lib/
317  mv curl-7.33.0-devel-mingw32/bin/* bin/
318  rm -rf curl-7.33.0-devel-mingw32
319  
320  
321  ** clean up
322  
323  rm *.zip
324  
325  
326  ** Building cgminer
327  
328  Below assumes you're building in a "build-win32" or similar directory
329  inside the cgminer directory. Fix up the -I and -L paths appropriately
330  if you're building in-tree or someplace else.
331  
332  Configure command:
333  
334  CPPFLAGS="-I`pwd`/../../cgminer-win32-deps/include" LDFLAGS="-L`pwd`/../../cgminer-win32-deps/lib -lcurldll" ../autogen.sh --prefix=/usr/local/i586-mingw32 --host=i586-mingw32msvc --build=i686-linux 
335  
336  ^^^ Plus whatever configure arguments you want to add. Note the paths
337      to cgminer-win32-deps that you may need to change.
338  
339  And make:
340  
341  make
342  
343  After cgminer builds, the next steps are the same as for native
344  building as given under "Copy files to a build directory/folder"
345  (DLLs can all be found in the cgminer-win32-deps/bin directory.)
346