2

I am trying to port some code to linux from Windows. I have gotten pretty far, but now I am stuck on an error with inheritance. But I can't figure out what's not working. It appears that It's not importing the header, but I can't figure out why because it seems to me that is should be working.

here is the error output:

/usr/bin/c++   -DHAVE_CLOGS -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_WIDGETS_LIB -std=c++11 -I/code/cuda/JF-Cut/src/build -I/code/cuda/JF-Cut/src/QVisualizer -I/code/cuda/clogs-install/include -I/usr/local/cuda-7.5/targets/x86_64-linux/include -isystem /opt/Qt/5.5/gcc_64/include -isystem /opt/Qt/5.5/gcc_64/include/QtWidgets -isystem /opt/Qt/5.5/gcc_64/include/QtGui -isystem /opt/Qt/5.5/gcc_64/include/QtCore -isystem /opt/Qt/5.5/gcc_64/./mkspecs/linux-g++    -fPIC -o CMakeFiles/QGCWidget.dir/Graph_Cut/QGCWidget.cpp.o -c /code/cuda/JF-Cut/src/QVisualizer/Graph_Cut/QGCWidget.cpp
In file included from /code/cuda/JF-Cut/src/QVisualizer/Graph_Cut/QGCWidget.cpp:44:0:
/code/cuda/JF-Cut/src/QVisualizer/Graph_Cut/../infrastructures/QError.h:45:11: error: ‘cl::Error’ has not been declared
 using cl::Error;
           ^
/code/cuda/JF-Cut/src/QVisualizer/Graph_Cut/../infrastructures/QError.h:48:1: error: expected class-name before ‘{’ token
 {
 ^
/code/cuda/JF-Cut/src/QVisualizer/Graph_Cut/../infrastructures/QError.h: In member function ‘void QError::serialize(std::ostringstream&, cl_int)’:
/home/sansomk/code/cuda/JF-Cut/src/QVisualizer/Graph_Cut/../infrastructures/QError.h:68:13: error: ‘cl::Error’ has not been declared
         cl::Error::serialize(s, code);

Here is the Code for QError.h

#ifndef QERROR_H
#define QERROR_H

#ifndef __CL_ENABLE_EXCEPTIONS
#define __CL_ENABLE_EXCEPTIONS
#endif
// removed #include "../3rdParty/cl/cl_stacktrace.hpp"
#if defined(__APPLE__) || defined(__MACOSX)
#include <OpenCL/cl.hpp>
#else
#include <CL/cl.hpp>
#endif

#define Q_LOGIC_ERROR       -100
#define Q_INVALID_ARGUMENT  -101
#define Q_LENGTH_ERROR      -102
#define Q_OUT_OF_RANGE      -103
#define Q_FUTURE_ERROR      -104
#define Q_RUNTIME_ERROR     -110
#define Q_RANGE_ERROR       -111
#define Q_OVERFLOW_ERROR    -112
#define Q_UNDERFLOW_ERROR   -113
#define Q_SYSTEM_ERROR      -114

using cl::Error;

class QError : public cl::Error
{
protected:
    cl_int level_;
    void serialize(std::ostringstream& s, cl_int code)
    {
        std::string error;
        switch (code)
        {
        case Q_LOGIC_ERROR: error = "Q_LOGIC_ERROR"; break;
        case Q_INVALID_ARGUMENT: error = "Q_INVALID_ARGUMENT"; break;
        case Q_LENGTH_ERROR: error = "Q_LENGTH_ERROR"; break;
        case Q_OUT_OF_RANGE: error = "Q_OUT_OF_RANGE"; break;
        case Q_FUTURE_ERROR: error = "Q_FUTURE_ERROR"; break;
        case Q_RUNTIME_ERROR: error = "Q_RUNTIME_ERROR"; break;
        case Q_RANGE_ERROR: error = "Q_RANGE_ERROR"; break;
        case Q_OVERFLOW_ERROR: error = "Q_OVERFLOW_ERROR"; break;
        case Q_UNDERFLOW_ERROR: error = "Q_UNDERFLOW_ERROR"; break;
        case Q_SYSTEM_ERROR: error = "Q_SYSTEM_ERROR"; break;
        }
        if (!error.empty()) s << " > " << error << ", ";
        cl::Error::serialize(s, code);
    }
public:
    QError(cl_int level, cl_int err, const char * errStr = NULL) : level_(level), cl::Error(err, errStr) {}

    ~QError() throw() {}

    cl_int level(void) const { return level_; }

    virtual const char * what() throw ()
    {
        std::ostringstream s;
        serialize(s, err_);
        errStr_ = s.str();
        return errStr_.c_str();
    }
};

#endif  // QERROR_H

1 Answers1

2

In order to use cl::Error you need to define __CL_ENABLE_EXCEPTIONS.

I can see you have it there, but that file is a header file. If you include OpenCL headers somewhere else earlier in the compilation unit (.cpp) without defining __CL_ENABLE_EXCEPTIONS. Then the later includes will simply skip (due to ifdefs in the header file to avoid multiple instances of the same .h file).

What you should do for these types of global compilation defines, is declare them in the command line.

 g++ ... -D__CL_ENABLE_EXCEPTIONS

That way you ensure the defines are enabled at the very beginning of the compilation.

DarkZeros
  • 8,235
  • 1
  • 26
  • 36
  • Is there anything wrong with there being multiple instances of the same header? – Kurt Sansom Mar 03 '16 at 23:57
  • It is not, you should add the header everywhere where you need it. But the global flags that define how the headers should behave have to be either defined in command line, or in a common place that affects once all the files. – DarkZeros Mar 04 '16 at 10:39