Compile leveldb c++ program in linux error?

匿名 (未验证) 提交于 2019-12-03 08:33:39

问题:

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/ 

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;  } 

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 

I don't know what's wrong.

I am new to Linux. Thank you very much!

回答1:

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



回答2:

Looks like the Makefile is incomplete.

With the current install, you need to edit the Makefile to link against snappy and to include -L/usr/local/lib instead of -L/usr/local/include.

(Will post pull request later)



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!