Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A weird error in in LevelDB while compiling a custom layer of caffe

#include <leveldb/status.h>
#include <leveldb/db.h>
#include <leveldb/write_batch.h>
...
int arg_offset = 0;
leveldb::DB* db1;
leveldb::Options options;
options.error_if_exists = true;
options.create_if_missing = true;
options.write_buffer_size = 268435456;
leveldb::WriteBatch* batch;
...
if (db_backend == "leveldb") 
{  
    // leveldb
    LOG(INFO) << "Opening leveldb " << argv[arg_offset+2];
    leveldb::Status status1 = leveldb::DB::Open(options, argv[arg_offset+2], &db1);
    CHECK(status1.ok()) << "Failed to open leveldb " << argv[arg_offset+2];
    batch = new leveldb::WriteBatch();
}

The above code snippet generates the following errors

$ g++ tools/convert_imageset_and_disparity.cpp -MMD -MP -pthread -fPIC -DCAFFE_VERSION=1.0.0-rc5 -DNDEBUG -O2 -DUSE_OPENCV -DUSE_LEVELDB -DUSE_LMDB -DWITH_PYTHON_LAYER -I/usr/include/python3.5m -I/usr/lib/python3.5/dist-packages/numpy/core/include -I/usr/local/include -I/usr/include/hdf5/serial -I/usr/include -I.build_release/src -I./src -I./include -I/usr/local/cuda-9.0/include -Wall -Wno-sign-compare -c -o .build_release/tools/convert_imageset_and_disparity.o 2> .build_release/tools/convert_imageset_and_disparity.o.warnings.txt \
    || (cat .build_release/tools/convert_imageset_and_disparity.o.warnings.txt; exit 1)



error: expected unqualified-id before ‘int’
         leveldb::Status status1 = leveldb::DB::Open(options, argv[arg_offset+2], &db1);
 -----------------^

error: ‘status1’ was not declared in this scope
         CHECK(status1.ok()) << "Failed to open leveldb " << argv[arg_offset+2];
---------------^

Compiler version :

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.9' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.9)

LevelDB is installed using sudo apt-get install libleveldb-dev

The same library is compiling a similar call to leveldb in another cpp file and it gets compiled successfully

void LevelDB::Open(const string& source, Mode mode) {
  leveldb::Options options;
  options.block_size = 65536;
  options.write_buffer_size = 268435456;
  options.max_open_files = 100;
  options.error_if_exists = mode == NEW;
  options.create_if_missing = mode != READ;
  leveldb::Status status = leveldb::DB::Open(options, source, &db_);
  CHECK(status.ok()) << "Failed to open leveldb " << source
                     << std::endl << status.ToString();
  LOG(INFO) << "Opened leveldb " << source;
}

Can someone help me to debug this error: expected unqualified-id ?

An excellent tutorial on How to use LevelDB is listed here.

like image 471
Khurram Amin Avatar asked Mar 14 '18 11:03

Khurram Amin


1 Answers

Finally I was able to (atleast) resolve the compilation error. Here are the changes that I made:

  1. changed leveldb::Status status1 = leveldb::DB::Open(options, argv[arg_offset+2], &db1) to auto status1 = leveldb::DB::Open(options, argv[arg_offset+2], &db1) Thanks @ZivS for pointing it out.
  2. changed Makefile from LIBRARIES += glog gflags protobuf leveldb snappy \ lmdb boost_system boost_filesystem hdf5_hl hdf5 m \ opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs opencv_videoio to LIBRARIES += glog gflags protobuf leveldb snappy \ lmdb boost_system boost_filesystem hdf5_hl hdf5 m \ opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs opencv_videoio X11
  3. Then finally compiled with -std=c++11 flag

The code was able to compile. Will update once I load the LevelDB using the built object.

Edit 2 Compiled code is running successfully.

like image 126
Khurram Amin Avatar answered Oct 15 '22 21:10

Khurram Amin