-1

I am trying to work through this tutorial on OpenCL, on a Windows 10 dev system which has integrated Intel HD graphics. I have installed Intel's OpenCL SDK. I have added the include directory from the SDK install into Properties > C/C++ General > Paths and Symbols > Includes. I am using MinGW as my compiler for Eclipse

In response to a number of linker errors that popped up when I first tried to compile the project, I set up the linker in eclipse to point to opencl.lib as outlined in this answer.

That took care of the linker errors, but there's an offending line from the tutorial which makes it impossible for the tutorial boiler-plate to compile:

87 cl_int result = program.build({ device }, "");

Set up as I am, this gives me the following warning and error:

..\src\main.cpp:93:32: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
..\src\main.cpp:93:45: error: no matching function for call to 'cl::Program::build(<brace-enclosed initializer list>, const char [1])'

If I'm reading this correctly (I haven't used C++ since before C++11 was a thing), the compiler is first warning me that it doesn't properly recognize what {device} is supposed to be (a vector of devices which has only one entry in it, initialized earlier in the code). Then, since it doesn't recognize {device}, the compiler errors out because it can't find a signature for cl::Program::build with arguments that match whatever-the-heck it's interpreting {device} to be.

Following the warning's advice, I followed the instructions given in this answer to add the -std=c++11 option for the compiler. However, when I do that the linker errors come back. Trying to compile with these options results in about thirty errors which all basically say they can't find any reference for the CL calls in the library files. For example:

C:/Program Files (x86)/Intel/OpenCL SDK/6.3/include/CL/cl.hpp:1753: undefined reference to `clGetPlatformInfo@20'

How do I make the compiler behave? I think I remember reading somewhere that the order of compiler options in the command line matters withe regards to linking, could that be messing up my compile since I added the -std=c++11 option?

Frank
  • 544
  • 2
  • 14
  • 2
    You will not see linker errors until your code compiles successfully. So adding `-std=c++11` did not cause the link errors you just were not getting to that stage in the compile-link process as your program was not compiling successfully. You now only need to investigate why the linker is not finding the required library(s). – Richard Critten Jun 02 '17 at 18:19
  • That doesn't make sense, because I was seeing linker errors before I added the correct setting in **Properties > C/C++ Build > Settings > MinGW C++ Builder > Libraries** I didn't know if I needed to add that to the question(it's gone on pretty long already), but my troubleshooting history has gone from linker error, to C++11 error, and back to linker error again. Are there multiple stages in linking or something? – Frank Jun 02 '17 at 18:25
  • There are 4 main stages in building a C++ program: 1) pre-processing 2) compiling 3) assembling 4) linking . – Jesper Juhl Jun 02 '17 at 18:54
  • If I understand correctly, when I first got `undefined reference` errors it's because the preprocessor needed the `-l` options to find the library file so the external references would work. Then, I needed `-std=c++11` to finish compiling. Now, I'm getting errors while linking, even though what I've already done worked for pre-processing. Why would that happen? Why is my setup good enough for pre-process but not linking? How do I debug this? – Frank Jun 06 '17 at 14:46

1 Answers1

0

I (sort of) figured out why the compiler was unhappy--the library I was linking was the x64 library for OpenCL installed in [base Intel dir]\OpenCL SDK\6.3\lib\x64, but (I think?) my compiler is not set up to create x64 apps. When I link to the .lib file in OpenCL SDK\6.3\lib\x86 my linker errors disappeared.

Frank
  • 544
  • 2
  • 14