pooler / cpuminer

CPU miner for Litecoin and Bitcoin
https://bitcointalk.org/index.php?topic=55038.0
Other
2.77k stars 1.21k forks source link

mingw64 needs -DPTW32_STATIC_LIB in CFLAGS, link to pthreads build&install instructions #9

Closed czka closed 11 years ago

czka commented 11 years ago

Please add this info to README: to build minerd.exe from pooler-cpuminer-2.2.3.tar.gz in MinGW 64 on Windows 7 I had to add `-DPTW32_STATIC_LIB' to my CFLAGS at ./configure. Otherwise make fails with:

gcc -std=gnu99  -O3 -march=native -mtune=native -pipe   -o minerd.exe minerd-cpu-miner.o minerd-util.o minerd-sha2.o minerd-sha2-arm.o minerd-sha2-x86.o minerd-sha2-x64.o minerd-scrypt.o minerd-scrypt-arm.o minerd-scrypt-x86.o minerd-scrypt-x64.o -lcurldll compat/jansson/libjansson.a -lpthread -lws2_32 -lpthread
minerd-cpu-miner.o:cpu-miner.c:(.text+0x5dd): undefined reference to `__imp_pthread_mutex_lock'
minerd-cpu-miner.o:cpu-miner.c:(.text+0x5ee): undefined reference to `__imp_pthread_mutex_unlock'
minerd-cpu-miner.o:cpu-miner.c:(.text+0xd12): undefined reference to `__imp_pthread_mutex_lock'
minerd-cpu-miner.o:cpu-miner.c:(.text+0xd5c): undefined reference to `__imp_pthread_mutex_unlock'
minerd-cpu-miner.o:cpu-miner.c:(.text+0x15ac): undefined reference to `__imp_pthread_mutex_lock'
minerd-cpu-miner.o:cpu-miner.c:(.text+0x163d): undefined reference to `__imp_pthread_mutex_unlock'
minerd-cpu-miner.o:cpu-miner.c:(.text+0x1746): undefined reference to `__imp_pthread_mutex_lock'
minerd-cpu-miner.o:cpu-miner.c:(.text+0x1772): undefined reference to `__imp_pthread_mutex_unlock'
minerd-cpu-miner.o:cpu-miner.c:(.text+0x1b3d): undefined reference to `__imp_pthread_mutex_unlock'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.1/../../../../x86_64-w64-mingw32/bin/ld.exe: minerd-cpu-miner.o: bad reloc address 0x50 in section `.data'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.1/../../../../x86_64-w64-mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
make[2]: *** [minerd.exe] Error 1
make[2]: Leaving directory `/home/msieczkx/cpuminer-2.2.3'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/msieczkx/cpuminer-2.2.3'
make: *** [all] Error 2

Also, the README could mention the nice how-to on pthreads installation, for MinGW 64 users: http://www.mythtv.org/wiki/MythTV_on_Windows#libpthread_2 (mind the `libpthread.a' rename "trick").

As I'm a complete MingW newbie, it took me several hours to sort these 2 things out. Probably others would find such hints usefull.

dikidera commented 11 years ago

Hi, I used to compile x64 binaries for pooler, and my MinGW64 installation did not need the -DPTW32_STATIC_LIB switch, as statically linking pthreads in general is extremely hard, and not just using a simple switch.

Mind I ask if you compiled libpthread on your own?

czka commented 11 years ago

Yes, I have built ftp://sourceware.org/pub/pthreads-win32/pthreads-w32-2-9-1-release.tar.gz myself, according to instructions on http://www.mythtv.org/wiki/MythTV_on_Windows#libpthread_2. That went smooth.

My MinGW64 installation is TDM64 4.7.1, installed using their http://sourceforge.net/projects/tdm-gcc/files/TDM-GCC%20Installer/tdm-gcc-webdl.exe/download (this link is on http://tdm-gcc.tdragon.net/download in "On-Demand Installer" section). I have selected all options in the installer except for fortran, objc and openmp.

I added msys to my C:\mingw64 installation, using https://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/ (linked on http://mingw.org/wiki/Getting_Started), having chosen "MSYS Basic System" ONLY.

Then I had issues with linking during make, like I wrote above. Finally, my working configure line was:

LIBCURL='-lcurldll' CFLAGS='-DPTW32_STATIC_LIB -O3 -march=native -mtune=native -pipe' ./configure

The resulting minerd.exe works fine. It requires the following libs to be present along with it in the same dir, if ran from Windows cmd outside mingw64:

czka commented 11 years ago

P.S.

If you could describe a simpler procedure to obtain a working env of MinGW64 + MSYS + minerd build deps that would be lovely!

pooler commented 11 years ago

The Windows build instructions assume the use of a precompiled version of libpthread. I didn't personally test building with MinGW-w64 on Windows, but a couple of other users have had no problems when following the steps outlined in the README. The same instructions also worked for me when cross-compiling with MinGW-w64 under Linux.

czka commented 11 years ago

What MinGW-w64 distribution provide a precompiled libpthread? The TDM one doesn't.

pooler commented 11 years ago

I didn't mean using a MinGW-w64 distribution that includes pthreads support out of the box. I meant getting a precompiled version of the pthreads library from a third-party source. There's one here, for example.