cpp eclipse中的libcaffe错误

时间:2016-07-11 10:45:40

标签: caffe leveldb

我只想使用cpp来读取从caffe中提取的LevelDB功能。 我在eclipse中使用以下代码:

// Copyright 2014 BVLC and contributors.

#include <glog/logging.h>
#include <stdio.h>  // for snprintf
#include <google/protobuf/text_format.h>
#include <leveldb/db.h>
#include <leveldb/write_batch.h>
#include <string>
#include <vector>
#include <cassert>
#include <iostream>
#include <map>

//#include "cpp/sample.pb.h"
#include "caffe/proto/caffe.pb.h"  // for: Datum
using namespace caffe;
#define NUMBER_FEATURES_PER_IMAGE 16
using namespace std;

int main(int argc, char** argv)
{
    //google::InitGoogleLogging(argv[0]);
    if (argc < 2)
    {
        printf("ERROR! Not enough arguments!\nusage: %s <feature_folder>", argv[0]);
    exit(1);
    }

LOG(INFO) << "Creating leveldb object\n";
leveldb::DB* db;
leveldb::Options options;
options.create_if_missing = true;
leveldb::Status status = leveldb::DB::Open(options, argv[1], &db);
assert(status.ok());

leveldb::Iterator* it = db->NewIterator(leveldb::ReadOptions());
int i = 0;
double count = 0.0f;
for (it->SeekToFirst(); it->Valid(); it->Next())
{
    Datum d;
    d.clear_float_data();
    d.clear_data();
    d.ParseFromString(it->value().ToString());
    for (int j = 0; j < d.height(); ++j)
        count += d.float_data(j);
    i++;
}
assert(it->status().ok());

LOG(INFO) << "Number of datums (or feature vectors): " << i << "\n";;
LOG(INFO) << "Reduction of All Vectors to A Scalar Value: " << count << "\n";
delete it;
}

它构建没有错误,但在运行时说: / home / deep / cuda-workspace / ReadLevelDB / Debug / ReadLevelDB:加载共享库时出错:libcaffe.so.1.0.0-rc3:无法打开共享对象文件:没有这样的文件或目录

问题是什么?

1 个答案:

答案 0 :(得分:0)

你的程序找不到* .so。有三种方法:

  1. 在/ usr / lib中创建* .so的链接:
  2.   

    ln -s /where/you/install/lib/*.so / usr / lib

         

    sudo ldconfig

    1. 修改LD_LIBRARY_PATH:
    2.   

      export LD_LIBRARY_PATH = / where / you / install / lib:$ LD_LIBRARY_PATH

           

      sudo ldconfig

      1. 修改/etc/ld.so.conf:
      2.   

        vim /etc/ld.so.conf

        添加/ where / you / install / lib

          

        sudo ldconfig