在linux下编译leveldb c ++程序错误?

我已经安装leveldb在我的主目录~/local

 [~/temp/leveldb-1.15.0] $ make [~/temp/leveldb-1.15.0] $ cp -av libleveldb.* $HOME/local/lib/ [~/temp/leveldb-1.15.0] $ cp -av include/leveldb $HOME/local/include/ 

我的c ++程序是这样的:

 #include <assert.h> #include <iostream> #include "leveldb/db.h" using namespace std; int main(int argc,char * argv[]) { leveldb::DB* db; leveldb::Options options; options.create_if_missing = true; std::string dbpath = "tdb"; leveldb::Status status = leveldb::DB::Open(options, dbpath, &db); assert(status.ok()); std::string key1 = "grz"; std::string key2 = "grz-rt@63.com"; cout<<"Open db OK"<<std::endl; std::string value; leveldb::Status s ; s = db->Put(leveldb::WriteOptions(), key1, key2);/*key1和key2作为一对key-value对插入*/ s = db->Get(leveldb::ReadOptions(), key1, &value);/*根据key返回对应的value值*/ cout<<value<<std::endl; delete db;/*删除数据库*/ return 0; } 

我编译这个C ++程序是这样的:

 g++ -o Main Main.cpp ~/local/lib/libleveldb.a -lpthread -I ~/local/include/ 

但是我得到这样的错误:

 /public/home/kli/local/lib/libleveldb.a(table_builder.o): In function `leveldb::TableBuilder::WriteBlock(leveldb::BlockBuilder*, leveldb::BlockHandle*)': table_builder.cc:(.text+0x678): undefined reference to `snappy::MaxCompressedLength(unsigned long)' table_builder.cc:(.text+0x6b2): undefined reference to `snappy::RawCompress(char const*, unsigned long, char*, unsigned long*)' /public/home/kli/local/lib/libleveldb.a(format.o): In function `leveldb::ReadBlock(leveldb::RandomAccessFile*, leveldb::ReadOptions const&, leveldb::BlockHandle const&, leveldb::BlockContents*)': format.cc:(.text+0x5de): undefined reference to `snappy::GetUncompressedLength(char const*, unsigned long, unsigned long*)' format.cc:(.text+0x64e): undefined reference to `snappy::RawUncompress(char const*, unsigned long, char*)' collect2: ld returned 1 exit status 

我不知道什么是错的。

我是Linux新手。 非常感谢你!

libleveldb.a错过Snappy时,可能会在libsnappy.a在同一目录中。

看起来像Makefile是不完整的。

使用当前的安装,您需要编辑Makefile来snappy链接,并且包含-L/usr/local/lib而不是-L/usr/local/include

(稍后会提出请求)