Compilation error: invalid qualifiers on non-member function type with gcc 4.8.1
I am trying to install Caffe on another system (and I have tried either MKL or ATLAS) with the specs:
- OS: Ubuntu 14.04.1 LTS
- gcc version 4.8.1 (Ubuntu 4.8.1-2ubuntu1~12.04)
I think that it might be a bug in the gcc. I am opening an issue because someone might have a solution and it might help others too.
When I am compiling with MKL I am getting:
./include/caffe/util/math_functions.hpp: In function ‘void caffe::caffe_cpu_sign(int, const Dtype*, Dtype*)’:
./include/caffe/util/math_functions.hpp:137:390: error: invalid qualifiers on non-member function type
DEFINE_CAFFE_CPU_UNARY_FUNC(sign, y[i] = caffe_sign<Dtype>(x[i]));
./include/caffe/util/math_functions.hpp:137:390: error: invalid qualifiers on non-member function type
./include/caffe/util/math_functions.hpp:137:575: error: invalid qualifiers on non-member function type
DEFINE_CAFFE_CPU_UNARY_FUNC(sign, y[i] = caffe_sign<Dtype>(x[i]));
./include/caffe/util/math_functions.hpp:137:575: error: invalid qualifiers on non-member function type
./include/caffe/util/math_functions.hpp: In function ‘void caffe::caffe_cpu_sgnbit(int, const Dtype*, Dtype*)’:
./include/caffe/util/math_functions.hpp:143:392: error: invalid qualifiers on non-member function type
DEFINE_CAFFE_CPU_UNARY_FUNC(sgnbit, y[i] = (std::signbit)(x[i]));
./include/caffe/util/math_functions.hpp:143:392: error: invalid qualifiers on non-member function type
./include/caffe/util/math_functions.hpp:143:577: error: invalid qualifiers on non-member function type
DEFINE_CAFFE_CPU_UNARY_FUNC(sgnbit, y[i] = (std::signbit)(x[i]));
./include/caffe/util/math_functions.hpp:143:577: error: invalid qualifiers on non-member function type
./include/caffe/util/math_functions.hpp: In function ‘void caffe::caffe_cpu_fabs(int, const Dtype*, Dtype*)’:
./include/caffe/util/math_functions.hpp:145:390: error: invalid qualifiers on non-member function type
DEFINE_CAFFE_CPU_UNARY_FUNC(fabs, y[i] = std::fabs(x[i]));
./include/caffe/util/math_functions.hpp:145:390: error: invalid qualifiers on non-member function type
./include/caffe/util/math_functions.hpp:145:575: error: invalid qualifiers on non-member function type
DEFINE_CAFFE_CPU_UNARY_FUNC(fabs, y[i] = std::fabs(x[i]));
./include/caffe/util/math_functions.hpp:145:575: error: invalid qualifiers on non-member function type
./include/caffe/blob.hpp: In member function ‘const boost::shared_ptr<caffe::SyncedMemory>& caffe::Blob<Dtype>::data() const’:
./include/caffe/blob.hpp:83:81: error: invalid qualifiers on non-member function type
CHECK(data_);
./include/caffe/blob.hpp:83:81: error: invalid qualifiers on non-member function type
./include/caffe/blob.hpp: In member function ‘const boost::shared_ptr<caffe::SyncedMemory>& caffe::Blob<Dtype>::diff() const’:
./include/caffe/blob.hpp:88:81: error: invalid qualifiers on non-member function type
CHECK(diff_);
./include/caffe/blob.hpp:88:81: error: invalid qualifiers on non-member function type
./include/caffe/filler.hpp: In member function ‘virtual void caffe::ConstantFiller<Dtype>::Fill(caffe::Blob<Dtype>*)’:
./include/caffe/filler.hpp:40:79: error: invalid qualifiers on non-member function type
CHECK(count);
./include/caffe/filler.hpp:40:79: error: invalid qualifiers on non-member function type
./include/caffe/filler.hpp: In member function ‘virtual void caffe::UniformFiller<Dtype>::Fill(caffe::Blob<Dtype>*)’:
./include/caffe/filler.hpp:56:89: error: invalid qualifiers on non-member function type
CHECK(blob->count());
./include/caffe/filler.hpp:56:89: error: invalid qualifiers on non-member function type
./include/caffe/filler.hpp: In member function ‘virtual void caffe::GaussianFiller<Dtype>::Fill(caffe::Blob<Dtype>*)’:
./include/caffe/filler.hpp:72:89: error: invalid qualifiers on non-member function type
CHECK(blob->count());
./include/caffe/filler.hpp:72:89: error: invalid qualifiers on non-member function type
./include/caffe/filler.hpp: In member function ‘virtual void caffe::PositiveUnitballFiller<Dtype>::Fill(caffe::Blob<Dtype>*)’:
./include/caffe/filler.hpp:109:105: error: invalid qualifiers on non-member function type
DCHECK(blob->count());
./include/caffe/filler.hpp:109:105: error: invalid qualifiers on non-member function type
./include/caffe/filler.hpp:114:77: error: invalid qualifiers on non-member function type
CHECK(dim);
./include/caffe/filler.hpp:114:77: error: invalid qualifiers on non-member function type
./include/caffe/filler.hpp: In member function ‘virtual void caffe::XavierFiller<Dtype>::Fill(caffe::Blob<Dtype>*)’:
./include/caffe/filler.hpp:150:89: error: invalid qualifiers on non-member function type
CHECK(blob->count());
./include/caffe/filler.hpp:150:89: error: invalid qualifiers on non-member function type
./include/caffe/filler.hpp: In function ‘caffe::Filler<Dtype>* caffe::GetFiller(const caffe::FillerParameter&)’:
./include/caffe/filler.hpp:181:77: error: invalid qualifiers on non-member function type
CHECK(false) << "Unknown filler name: " << param.type();
./include/caffe/filler.hpp:181:77: error: invalid qualifiers on non-member function type
make: *** [.build_release/src/caffe/layers/power_layer.cuo] Error 1
When I am compiling with ATLAS I am also getting errors for every function that is defined using the processor's directives (unary and binary functions) in the mkl_alternate.hpp file:
./include/caffe/util/mkl_alternate.hpp: In function ‘void vSqr(int, const Dtype*, Dtype*)’:
./include/caffe/util/mkl_alternate.hpp:34:378: error: invalid qualifiers on non-member function type
DEFINE_VSL_UNARY_FUNC(Sqr, y[i] = a[i] * a[i]);
./include/caffe/util/mkl_alternate.hpp:34:378: error: invalid qualifiers on non-member function type
I am trying to resolve this problem and I have found that:
- The system uses CUDA-6.5 (also 6.0 is installed but it does not make any difference)
- The installed driver is
340.29(returned by$nvidia-smi) - Caffe compiles successfully in CPU-only mode.
- The error happens when it uses for the first time the nvcc for compilation (after successfully compiling
common.cppwith the g++):
/usr/local/cuda-6.5/bin/nvcc -ccbin=g++ -Xcompiler -fPIC -DNDEBUG -O2 -DUSE_MKL -I/usr/include/python2.7 -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/local/include -I.build_release/src -I./src -I./include -I/usr/local/cuda/include -I/opt/intel/mkl/include -gencode arch=compute_20,code=sm_20 -gencode arch=compute_20,code=sm_21 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -c src/caffe/layers/power_layer.cu -o .build_release/src/caffe/layers/power_layer.cuo 2> .build_release/src/caffe/layers/power_layer.cuo.warnings.txt || (cat .build_release/src/caffe/layers/power_layer.cuo.warnings.txt; exit 1)
I will keep working on that. If anyone has an idea on where it might be the problem, I will look into that.
I made some tests, and I removed the CHECK() and DCHECK() functions (only) from the headers that are included and caused the problem, and the program compiled. So I am guessing that there might be a problem with linking the glog/logging.h header with the rest of the program. I checked and glog is installed, so I am trying to find what causes the problem.
I think I solved that. Unfortunately, this was a bug with gcc-4.8.1. I updated gcc to gcc-4.8.2 and everything works OK. I compiled the master and dev and the error has not showed up.