Author

Topic: Building cgminer on Windows with MinGW, step-by-step (2015-07-10) (Read 8729 times)

newbie
Activity: 28
Merit: 1
I just want to say thanks for the visual aides.  I have been at this for 2 days trying to compile my own cgminer miner with little compiling and unix command skills and managed to finally get it done from trial and error.

First attempt was following these steps here from off Window Server 2016, it was all good till I got to the ./autogen part and I found out that Windows Server 2016 suffers from the Windows 10 Creators Update build bug that breaks gcc.

Second attempt was from my Windows 7 system, while following this guide I thought I get clever and try that MSYS that was mentioned in the steps, and that lead me to installing MSYS2 and trying to set this up with using that shell and it's -pacman command.  
Despite my novice skills I got further than my first attempt but hit the wall at trying to compile the CFLAGS ./configure ,  I constantly kept getting No Inputted mining & latter kept receiving OPENCL Detection Overrided , or OPENCL not found.  


In the latter of this troubleshoot and research I discovered that this information here that I had been following have been slightly in vain, getting CGMINER from the official github when the official github has a CGMINER that's been scripted of any GPU support.     Undecided

But determined to get through this. I discovered version 3.7.2 being the last version that had GPU support, and found a Github repository of that.

Went back to the drawing board and decided to do old school, and by that I mean try to utilize every piece of software used by the author from that outdated Windows_build,  this method led me to VICTORY.  

and here's the secret to how I did it, and how anyone else reading this could achieve it.  

USE

the WayBackmachine!  Cool


Turns out most of those broken links are still accessible if accessed from the WayBackMachine as well as the download files  (with the exception of the Mingw, which that version ck used mingw-get-inst-20120426.exe is available on SourceForge!)

archive.org site is a God-sin.
newbie
Activity: 39
Merit: 0
Thank you post help me a lot but still there were some issues. Now i have my own cgminer with gridseed functions enabled
member
Activity: 238
Merit: 10
Hi
I ty this guide but I still have errors...

It's about sleep and nanosleep already declared in pthread...
Have you got an idea ?
newbie
Activity: 6
Merit: 0
Hi!

Follow your instruction i got this error:

In file included from util.h:32:0,
                 from miner.h:29,
                 from compat.h:12,
                 from api.c:28:
c:\mingw\include\ws2tcpip.h:16:2: error: #error "ws2tcpip.h is not compatible wi
th winsock.h. Include winsock2.h instead."
 #error "ws2tcpip.h is not compatible with winsock.h. Include winsock2.h instead
."
  ^~~~~
In file included from c:\mingw\include\ws2tcpip.h:19:0,
                 from util.h:32,
                 from miner.h:29,
                 from compat.h:12,
                 from api.c:28:
c:\mingw\include\winsock2.h:49:2: error: #error "Including after insock.h> is unsupported."
 #error "Including after is unsupported."
  ^~~~~
c:\mingw\include\winsock2.h:50:2: warning: #warning "Falling back to WinSock v1.
1 protocol." [-Wcpp]
 #warning "Falling back to WinSock v1.1 protocol."
  ^~~~~~~
In file included from util.h:32:0,
                 from miner.h:29,
                 from compat.h:12,
                 from api.c:28:
c:\mingw\include\ws2tcpip.h:124:8: error: redefinition of "struct ip_mreq"
 struct ip_mreq {
        ^~~~~~~
In file included from c:\mingw\include\ptw32_errno.h:176:0,
                 from c:\mingw\include\_ptw32.h:157,
                 from c:\mingw\include\pthread.h:76,
                 from compat.h:9,
                 from api.c:28:
c:\mingw\include\winsock.h:411:8: ghi chú: originally defined here
 struct ip_mreq
        ^~~~~~~
In file included from util.h:32:0,
                 from miner.h:29,
                 from compat.h:12,
                 from api.c:28:
c:\mingw\include\ws2tcpip.h:298:13: error: expected "=", ",", ";", "asm" or "__a
ttribute__" before "freeaddrinfo"
 void WSAAPI freeaddrinfo (struct addrinfo*);
             ^~~~~~~~~~~~
c:\mingw\include\ws2tcpip.h:299:12: error: expected "=", ",", ";", "asm" or "__a
ttribute__" before "getaddrinfo"
 int WSAAPI getaddrinfo (const char*,const char*,const struct addrinfo*,
            ^~~~~~~~~~~
c:\mingw\include\ws2tcpip.h:301:12: error: expected "=", ",", ";", "asm" or "__a
ttribute__" before "getnameinfo"
 int WSAAPI getnameinfo(const struct sockaddr*,socklen_t,char*,DWORD,
            ^~~~~~~~~~~
make[2]: *** [sgminer-api.o] Error 1
make[2]: Leaving directory `/home/Administrator/sgminer'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/Administrator/sgminer'
make: *** [all] Error 2


Could you help me with this.

Thanks
Jay Anh
hero member
Activity: 686
Merit: 500
FUN > ROI
For the love of .. please don't quote this entire post in any reply, or see your reply deleted - If you must quote, quote only relevant parts.
This is a lengthy and picture-heavy rundown of compiling cgminer on Windows by somebody who hasn't done so in over a year and ran into various problems doing so from scratch - procedure for 2015-07-06.

If you don't need any code changes, just use the regular cgminer builds.
If you do need a custom Windows binary, consider cross-compiling in a Linux environment.
If you enjoy mild frustration, continue reading Smiley

Although the result works (well, so far), there's always a chance that it doesn't perform the same as the official builds due to differences in library versions, kludgy code edits to get things to compile, and so on.

It's also entirely possible that things could be done more efficiently ( in terms of compiling - starting this thread out step-by-clicking-step on purpose ) - if so, leave your replies Smiley



"build cgminer for windows"
So you want to build cgminer for Windows, and presumably on Windows.

First thing you're likely to do is hit up google with exactly those search terms.


Lucky me, the very top result points to a document at the official github repository, while the third result in my case braces me for things to come.  October 2012 is a bit too 3 years ago to dive into that thread, though, so carry on and follow the first result.  "Native WIN32 setup and build instructions (on mingw32/Windows)".  Sounds promising, though what's mingw32?

https://github.com/ckolivas/cgminer/blob/master/windows-build.txt

Carry on reading and - aha - mingw32 is something I'll have to install.  At this point, you may wish to do a quick read through the entire document and then come back here.


Download and install MinGW
Another site to go to, follow the link.

http://www.mingw.org/wiki/Getting_Started

Now the next instruction refers to a "Download and run the latest mingw-get-inst version." link.  That no longer exists.


Instead, scroll down the page to find "Graphical User Interface Installer" and the mingw-get-setup.exe link, and click that instead.

https://sourceforge.net/projects/mingw/files/latest/download

You'll end up at Sourceforge - probably will for the foreseeable time, despite sourceforge's recent snafus, as a lot of mingw depends on things hosted at sourceforge - with a countdown time before the download begins.  Once the download has completed, launch the downloaded MinGW installer.



Click through the bunch of boring install screens - but keep an eye out in case it gets repackaged with 'value added' software.  Note that in my case, I changed the drive from C: to E: because reasons.  Yes, this installer downloads additional files.  That'll be a running theme in this post.


Eventually you'll end up with a new screen labeled MinGW Installation Manager.  Here you can choose which components to include in your MinGW installation.


The instructions suggest to select basically everything - with poor Fortran singled out as not having been selected by the cgminer author.  You'll want to select the following components:
  • mingw-developer-toolkit
  • mingw32-base
The first one will also automatically select the msys-base component.  To select the components for installation, click on the checkbox and choose Mark for Installation

Note: If you want to save a few steps later on, expand the tree on the left to All Packages > MinGW > MinGW Libraries, and also select mingw32-pthreads-32 of class dev (doesn't hurt to select 'doc' and 'lic' as well).

Once the components have been marked for installation, go to the Installation menu and choose Apply Changes.  You'll get a new dialog that shows what changes will be made (in this case, only new/upgraded packages) - in there, click Apply.  The MinGW Installation Manager will now download (yep) and install those components - this takes a while.  Once it is done, the components should be marked as installed in the manager, and you can choose Installation and then Quit to exit the manager.


Run the MSYS shell / create your user directory
The next instruction suggests that MSYS shell should be run by going through the Start menu.  Only one problem: it's not there.  If you're on Windows 8, the 'metro' start menu will inform you that the only 'MinGW' it knows of is that manager.


Off to google I go, to find out why I can't find MinGW shell, and luckily I'm not alone.  The first result is a good hit, though the first answer goes off on uninstalling and reinstalling and another mentions setting up a shortcut (if you must, by all means) which can be entirely ignored, msoliman has the tl;dr version, I have to launch a batch file. Success!  That certainly does look like a command line interface of some sort.  


Install libpdcurses
The next section in the instructions suggests to install libpdcurses by a couple of commands.  Unfortunately, the very first command throws an  error: sh: mingw-get: command not found.   Thankfully, the earlier page that explained how to launch the shell also had a hint in there that I happened to read: the installer might not actually perform all that needs doing, and a post-install batch file will have to be run and its instructions followed.  Once done, mingw-get can be found just fine and the libpdcurses libraries download (yep) and install without a problem.

Code:
mingw-get install mingw32-libpdcurses
mingw-get install mingw32-pdcurses

Copy CGMiner source to your MSYS working directory
...is the title of the next section in the instructions, but how do I go about getting the cgminer source, exactly?  Well, the github repository that holds the instructions document is also the source repository, simply click on through to cgminer, and then click on the Download ZIP button to download the entire source repository as a ZIP file.  Open that ZIP file, and follow the instructions by copying the files - I recommend just copying the cgminer-master folder - and pasting it into your MSYS user folder in MinGW\msys\1.0\home\USERNAME\.

https://github.com/ckolivas/cgminer/blob/master/windows-build.txt

GPU mining optional
GPU mining.. optional, you say?  Good, let me skip this.
( If you want GPU mining - go ahead.. that's probably a whole 'nother can of worms, though. )


Install GTK-WIN
Good, more bits to download and install.  Just click all the appropriate links and buttons, make sure there's no 'value added' bits and pieces, and continue following the instructions.  Make sure you copy the files that the instructions say to copy!  If you can't find the files to copy (e.g. you can't find Program Files (x86) or Program Files), make sure your Windows Explorer or other file manager is set to display hidden files and folders.

http://sourceforge.net/projects/gtk-win/

Install pkg-config
More. Again, click the appropriate links and buttons, following the instructions, with the one caveat that it's pkg-config you're looking for, and not pkg-cfg.  By now you should be  used to opening downloaded files, and copying files from one location to another, so let me skip those screenshots.

http://www.gtk.org/download/win32.php

Install libcurl
Once again, click the appropriate links and buttons, following the instructions, with the caveat here being that you shouldn't try copying all the files in the 3 folders mentioned individually - just copy the 3 folders, and paste them into the MinGW installation folder.  Note that you may get a complaint about zlib1.dll already existing - skip that file (at this time the one that comes with MinGW is newer than the one that comes with libcurl).

http://curl.haxx.se/download.html#Win32

The instructions also ask you to edit a file.  Find the file, right-click it, and open it in your editor.  If you don't have a good editor - well, I like notepad++ ( https://notepad-plus-plus.org/ ) as a lightweight one.  Note that if you try opening files with regular Windows Notepad, the file may not be interpreted correctly, with linebreaks missing.  This is because Linux uses a different linebreak format from Windows and Windows Notepad basically screws up.  Make sure you actually save the file when done editing.


Build cgminer.exe
Hurrah!  Let's, by all means, actually build cgminer.exe!  Typing cd cg is the way to go, gets you straight into the cgminer-master directory.  


The next two instructions you should skip.  Not just because the first one is optional, but because the second one is obsolete, as per the cgminer developer's own statement on this forum.  Instead, run autogen.sh by simply typing that and hitting enter.  This shell script will take a while to run.

Code:
autogen.sh

Next up is setting the compile flags.  As I didn't include GPU mining support, those should be disabled with.  As the point of compiling cgminer from scratch was to play with Icarus-comms type device, I enabled that option.

Code:
CFLAGS="-O2 -msse2" ./configure --disable-gpu --disable-adl --enable-icarus

Alas, an error occurs.  If you took my advice a few steps back and enabled the mingw32-pthreads-32 component, you should not be getting this error. If you didn't take that advice, here's how to resolve the error:

Code:
mingw-get install pthreads

The MinGW Installation Manager will also show the component as installed if you check now. ( Make sure to close it again before proceding further. )


Once installed, re-run the compile flags command (press the up arrow key to go back to previous commands you entered so save from typing them in manually again), and it should run through without any problems.


The next command is make which actually starts the process of compiling the source into a binary.  Run that command, and... more errors.

Code:
make

Googling the error yields some results - the first result is a bit of a red herring, but does helpfully point out that one should probably use MSYS2 as MSYS is outdated .. great, but ignore - the third result of which is most helpful, as it points out that this is an issue with MinGW itself introduced not all that long ago (and well after the cgminer build instructions).  Following the links leads to a patch file which, when applied, effective disables some code.


Rather than applying it, opening the file shows exactly what needs to be done.  The #ifdef 0 ... #endif basically causes the code within to never be evaluated by the compiler.  Find the file that needs to be edited at MinGW\include\unistd.h, edit it, and make the appropriate changes.  Don't forget to save the file.


At this point, run the compiler flags command and make again, and... another error.


In this case the error is because the sleep function got defined with different formats.  The one from cgminer I'll probably want to keep, so instead I just commented out the ones from MinGW\include\unistd.h.


Again, run the compiler flags command and make again, and... success!  cgminer source successfully compiled into cgminer.exe


The next step in the instructions suggests to strip it of debug bits, so why not.

Code:
strip cgminer.exe

Running cgminer.exe
To actually run cgminer.exe, it has to be put together with some libraries it depends on into a folder.  The instructions mention a bunch of libraries, find them as stated, copy, and paste them all together into a (new) folder, then launch cgminer.exe to get the next error.


Update for 2015-07-10: You may find that you get more HW errors with this as built. Instead of using the file pthreadGC2.dll as listed, download an older version from http://ftp://sourceware.org/pub/pthreads-win32/prebuilt-dll-2-8-0-release/lib/pthreadGC2.dll and use that instead.  For reference, see the cross-compile build notes.

I'm missing a file, obviously.  Thankfully, that file is available as MinGW\bin\libgcc_s_dw2-1.dll, so copy it from there to the same folder as cgminer.exe, then try again - oh boy, it runs!




Zadig
Ah crap.  Zadig.  If you get the error about needing to replace drivers, here's a very quick bonus section on running zadig so that the newer cgminer versions can find some miners.  If you don't get this error, you should already be mining.
Zadig is a utility that can replace vendor-specific USB serial drivers, such as those from Silicon Labs, FTDI, etc. with a more universal USB serial driver.  Google Zadig, make sure you get the official page, download the version for Vista or later unless you're on XP - the executable you get is the program, not an installer - launch, go to Options and then List All Devices to actually list the devices, pick the appropriate one from the list - which is easier if you don't have a bunch of serial devices plugged in - make sure the replacement driver is WinUSB, click the Replace Driver button, wait for Zadig to do its thing, then unplug and replug the device.


If all is well, re-run cgminer.exe and off you go!




GekkoScience Compac
If you came here because you wanted to mess with higher frequencies on a GekkoScience Compac, and just can't wait for official builds, here's the changes you'll have to make before building cgminer:
Edit the cgminer.c file and adjust three sections, essentially changing '250' to '450'.


Edit the driver-icarus.c file and adjust three sections, essentially changing '250' to '450' and adding the higher frequencies to the look-up table.

Frequencies and hex codes from BM1384 datasheet:
Code:
{ 275, 0x0a82 },
{ 300, 0x0b82 },
{ 325, 0x0c82 },
{ 350, 0x0d82 },
{ 375, 0x0e82 },
{ 400, 0x08f2 },
{ 425, 0x0801 },
{ 450, 0x0881 },
Jump to: