Unable to compile OpenCL on Cygwin - Windows specific variables
Closed this issue · 2 comments
The environment I am using is Cygwin64. The original makefile works perfectly with the original process.cpp.
I am trying to set up the environment for OpenCL using the same include files from CW4, adding the following lines to process.cpp:
#ifndef _WIN32
#include <alloca.h>
#endif
#define CL_USE_DEPRECATED_OPENCL_1_1_APIS
#define __CL_ENABLE_EXCEPTIONS
#include "CL/cl.hpp"
This is the error I see using both Cmake and a regular makefile:
Relating to this part of the code:
#if !(defined(_WIN32) || defined(_WIN64))
#include <unistd.h>
void set_binary_io()
{}
#else
// http://stackoverflow.com/questions/341817/is-there-a-replacement-for-unistd-h-for-windows-visual-c
// http://stackoverflow.com/questions/13198627/using-file-descriptors-in-visual-studio-2010-and-windows
// Note: I could have just included <io.h> and msvc would whinge mightily, but carry on
#include <io.h>
#include <fcntl.h>
#define read _read
#define write _write
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
void set_binary_io()
{
_setmode(_fileno(stdin), _O_BINARY);
_setmode(_fileno(stdout), _O_BINARY);
}
#endif
It seems that it is going to branch which should only execute in a Windows environment. The code seems to compile OK when I comment out the Windows only branch. It seems confusing how _WIN32 and _WIN64 can be found on cygwin. What would be a good way to resolve this issue?
Just had an idea and found this in the Khronos cl.hpp:
#ifdef _WIN32
#include <windows.h>
#include <malloc.h>
#if defined(USE_DX_INTEROP)
#include <CL/cl_d3d10.h>
#endif
could this probably be the cause?
or maybe something else in the header files that is causing _WIN32 or _WIN64 to be found?
I would recommend that if you are going to compile under cygwin, then you simply
remove the #ifdef
code that checks to see if it is running on native windows.
You have complete control over your code, so if you decide you are only going to
compile in unix-y environments (cygwin, linux, AWS), then take anything unneeded out
(I was tempted take the windows code out anyway, but I know some people like
to use devstudio for debugging).
Otherwise, you could do something like modifying:
#if !(defined(_WIN32) || defined(_WIN64))
to
#if defined(DEFINITELY_UNIX) || !(defined(_WIN32) || defined(_WIN64))
then adding:
CPPFLAGS += -DDEFINITELY_UNIX=1
to your makefile.