在Linux上编译leveldb C ++程序错误? [英] Compile leveldb c++ program in linux error?

查看:321
本文介绍了在Linux上编译leveldb C ++程序错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这样在主目录~/local中安装了leveldb.

I have install leveldb in my home directory ~/local like this.

[~/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 ++程序是这样的:

My c++ program like this:

#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 ++程序:

I compile this C++ program like this:

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

但是我得到这样的错误:

But I get the error like this:

/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的新手.非常感谢你!

I am new to Linux. Thank you very much!

推荐答案

libleveldb.a在链接时错过了Snappy,该链接可能在同一目录的libsnappy.a中.

libleveldb.a misses Snappy when being linked which would be probably in libsnappy.a in the same directory.

这篇关于在Linux上编译leveldb C ++程序错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆