Reputation: 33699
I'm getting a linker error from the OpenCL 2.0 C++ bindings header file cl2.hpp. All my headers files come directly from the Khronos OpenCL registry and I build the OpenCL.lib file myself. I don't get an error using the OpenCL 1.2 C++ bindings header file.
I am using Qt 5.5.0 and Visual Studio C++ 2013 with Windows7 64-bit.
The error is related to multiply defined symbols in multiple source files.
mainwindow.cpp.obj:-1: error: LNK2005: "enum cl::QueueProperties __cdecl
cl::operator|(enum cl::QueueProperties,enum cl::QueueProperties)"
(??Ucl@@YA?AW4QueueProperties@0@W410@0@Z) already defined in main.cpp.obj
I don't understand why the compiler is saying this is already defined.
I have narrowed down the problem to this code in the cl2.hpp file
QueueProperties operator|(QueueProperties lhs, QueueProperties rhs)
{
return static_cast<QueueProperties>(static_cast<cl_command_queue_properties>(lhs) | static_cast<cl_command_queue_properties>(rhs));
}
When I comment that code out my project compiles and runs fine. Do you have any clue to what this problem is? Is it a poor design in the cl2.hpp header file?
Upvotes: 0
Views: 704
Reputation: 9925
The issue is that the offending function is a non-inline member function. This means that when cl2.hpp
is included from multiple source files, there will be multiple copies of the function definition that will clash when these object files are linked together.
The simple solution is to mark the offending function as inline
(as many of the other functions in the header already are).
Upvotes: 1