I tried to compile in Windows 10(MinGW64) with [gcc version 11.2.0 (Rev5, Built by MSYS2 project)].
Changing optimization level to -O1 solved the problem and it compiled successfully.
I never got mingw/msys2 working from a Windows host but if you've gotten this far it's worth pursuing.
If you have git an issue would be appropriate for tracking.
It compiles ok with gcc 11.2.0 on Ubuntu-21.10 but I don't have mingw setup for that. I currently use gcc 9.3.0
in Ubuntu 20.04 to build the Windows binaries as documentd on the Wiki.
It's odd that it would compile depending on compiler optimizations, also that it's old code.
If I can identify what code is causing it there might be a better way to write it even if the bug isn't obvious.
Since it compiles with -O1, unless there's a switch that turns a -O1 warning into a -O2 error, there could also
be a compiler bug. [Not likely]
Edit: sph_jh doesn't include any Windows compatibility code so mingw compiles the same source code as Linux.
Edit: Not needed anymore:
The error you posted wasn't very useful, it only identified the file, not the line. Are there earlier errors with more info?
Relevant warnings, if any, from the -O1 compile might also be useful in figuring out why this switch makes a difference.If you can document your procedure I'm sure a lot of people would be grateful, including me. The current procedure
using a full Linux installation, VM or separate PC, is quite cumbersome.Update:
I got msys2 installed and was able to get to the same point as you.
The good news is if the compiler can get past sph_jh.c it will compile successfully. I haven't tried running it yet.
The bad news is 5 lines of code need to be commented out:
#define Sb(x0, x1, x2, x3, c) do { \
x3 = ~x3; \
x0 ^= (c) & ~x2; \
tmp = (c) ^ (x0 & x1); \
/* x0 ^= x2 & x3; */ \
/* x3 ^= ~x1 & x2; */ \
x1 ^= x0 & x2; \
/* x2 ^= x0 & ~x3; */ \
/* x0 ^= x1 | x3; */ \
/* x3 ^= x1 & x2; */ \
x1 ^= tmp & x0; \
x2 ^= tmp; \
} while (0)
This compiles but if any one line is uncommented it will fail.
I have no idea what the problem is.
The code is very old and stable and hasn't had any problems before.
GCC 11.2 works on Ubuntu-21.10 native and mingw.
It works with msys2 with -O1 but not -O3.
The compiler can't provide a reason for the error.
The main difference between the Ubuntu mingw and Windows mingw, other than the OS itself, is msys2.
I can't make sense of this, could be a compiler bug, msys2 bug, some incompatibility?
I couldn't find another version of GCC in the package repo but maybe an older version of msys2 might
not have this bug.
It's still a lot farther than I've gotten before with msys2.
Update2:
It appears the compiled cpuminer.exe will only run from the msys2 environment. There are 4 missing dll's when running
directly from Windows, some are built by hand for the existing Windows package which means the same would have to be done
to make the msys2 build portable. So it doesn't look suitable for portability, maybe just for Windows geeks that want to compile
themselves.
Assuming the compile issue can be solved, there is the question of performance. There's no point in testing
performance with different compiler optimizations or butchered code. Using cygwin the perfomance is lower
than the current mingw build package. I believe msys2 uses some components from cygwin so it may also be slower.