OpenCL-Headers
OpenCL-Headers copied to clipboard
Error when compiling for MinGW from Cygwin with gcc 7.4.0
I tried to compile some code with latest headers (from HEAD) using x86_64-w64-mingw32-g++ 7.4.0 crosscompiler shipped with Cygwin. I got following errors:
In file included from /usr/x86_64-w64-mingw32/sys-root/mingw/include/intrin.h:41:0,
from ./CL/cl_platform.h:380,
from ./CL/cl.h:35,
from ./CL/opencl.h:47,
from CL/cl.hpp:170,
from RakeSearchOpenCL.h:6,
from main.cpp:19:
/usr/x86_64-w64-mingw32/sys-root/mingw/include/psdk_inc/intrin-impl.h:1848:42: error: macro "__cpuid" requires 5 arguments, but only 2 given
void __cpuid(int CPUInfo[4], int InfoType);
^
/usr/x86_64-w64-mingw32/sys-root/mingw/include/psdk_inc/intrin-impl.h:1851:42: error: macro "__cpuid" requires 5 arguments, but only 2 given
void __cpuid(int CPUInfo[4], int InfoType) {
^
In file included from ./CL/cl_platform.h:380:0,
from ./CL/cl.h:35,
from ./CL/opencl.h:47,
from CL/cl.hpp:170,
from RakeSearchOpenCL.h:6,
from main.cpp:19:
/usr/x86_64-w64-mingw32/sys-root/mingw/include/intrin.h:1117:44: error: macro "__cpuid" requires 5 arguments, but only 2 given
__MACHINEI(void __cpuid(int a[4],int b))
^
In file included from /usr/x86_64-w64-mingw32/sys-root/mingw/include/intrin.h:41:0,
from ./CL/cl_platform.h:380,
from ./CL/cl.h:35,
from ./CL/opencl.h:47,
from CL/cl.hpp:170,
from RakeSearchOpenCL.h:6,
from main.cpp:19:
/usr/x86_64-w64-mingw32/sys-root/mingw/include/psdk_inc/intrin-impl.h:1848:6: error: variable or field ‘__cpuid’ declared void
void __cpuid(int CPUInfo[4], int InfoType);
^~~~~~~
/usr/x86_64-w64-mingw32/sys-root/mingw/include/psdk_inc/intrin-impl.h:1851:6: error: variable or field ‘__cpuid’ declared void
void __cpuid(int CPUInfo[4], int InfoType) {
^~~~~~~
/usr/x86_64-w64-mingw32/sys-root/mingw/include/psdk_inc/intrin-impl.h:1852:4: error: expected primary-expression before ‘__asm__’
__asm__ __volatile__ (
^~~~~~~
/usr/x86_64-w64-mingw32/sys-root/mingw/include/psdk_inc/intrin-impl.h:1852:4: error: expected ‘}’ before ‘__asm__’
In file included from ./CL/cl_platform.h:380:0,
from ./CL/cl.h:35,
from ./CL/opencl.h:47,
from CL/cl.hpp:170,
from RakeSearchOpenCL.h:6,
from main.cpp:19:
/usr/x86_64-w64-mingw32/sys-root/mingw/include/intrin.h:1117:5: error: variable or field ‘__cpuid’ declared void
__MACHINEI(void __cpuid(int a[4],int b))
^
In file included from CL/cl.hpp:170:0,
from RakeSearchOpenCL.h:6,
from main.cpp:19:
./CL/opencl.h:55:1: error: expected declaration before ‘}’ token
}
Problem is caused by following part of code in cl_platform.h
#if defined( __MINGW64__ )
#include <intrin.h>
#else
#include <xmmintrin.h>
#endif
There are 3 similar code clocks there. When I commented out parts for __MINGW64__
, code compiled without errors.
I use SSE/AVX intrinsics for more than 2 years, and during that time I always included headers as suggested in Intel Intrinsics Guide. Looks that MinGW shipped with Cygwin has correct headers and does not need any workarounds. If you need them for some other reason, some extra checks will be needed here.
I’m having literally the same exact issue. The quick hack was much appreciated, though I wish this would be somehow fixed permanently.
@ssterling If you can help us cook up cross-compiling scripts into our CI, it will always be tested and won't regress in the future. I'd be glad to help out, but propagating our CI through the rest of the OpenCL repos is on the top of my list now. The Windows runners in GitHub Actions is fairly tool rich and IIRC there are MinGW toolchains available too.
Just to be clear, the quick hack mentioned above is to change this:
#if defined( __MINGW64__ )
#include <intrin.h>
#else
#include <xmmintrin.h>
#endif
to this?
#include <xmmintrin.h>
If we know when xmmintrin.h
was added could we add a check for e.g. __MINGW32_MAJOR_VERSION
or __MINGW64_VERSION_MAJOR
instead? Or, has it been sufficiently long that we should just use xmmintrin.h
unconditionally?