简体   繁体   English

在编译自定义caffe层时,LevelDB中出现了一个奇怪的错误

[英]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 使用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 同一个库正在编译另一个cpp文件中对leveldb的类似调用,并且它被成功编译

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 ? 有人可以帮我调试这个error: expected unqualified-id

An excellent tutorial on How to use LevelDB is listed here . 这里列出 How to use LevelDB的优秀教程。

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. 更改了leveldb::Status status1 = leveldb::DB::Open(options, argv[arg_offset+2], &db1)auto status1 = leveldb::DB::Open(options, argv[arg_offset+2], &db1)谢谢@ZivS指出来了。
  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 改变生成文件从LIBRARIES += glog gflags protobuf leveldb snappy \\ lmdb boost_system boost_filesystem hdf5_hl hdf5 m \\ opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs opencv_videoioLIBRARIES += 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 然后最后用-std=c++11标志编译

The code was able to compile. 代码能够编译。 Will update once I load the LevelDB using the built object. 一旦我使用构建的对象加载LevelDB,就会更新。

Edit 2 Compiled code is running successfully. 编辑2编译的代码正在成功运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM