在安装了leveldb和snappy,macOS

时间:2018-06-14 19:32:16

标签: c++ leveldb

我想验证leveldb安装。我有一个仅包含levelDB::DB::Open()函数的main函数。我使用brew install安装了snappy和leveldb。我也安装了1.67。我有GCC 8.1。我正在运行macOS 10.13.5。

我的源文件如下所示:

int main(void) {
    leveldb::DB *db;
    leveldb::Options options;
    options.create_if_missing = true;
    auto err = leveldb::DB::Open(options, "../tmpDB", &db);
    if (err.ok()) {
        std::cout << "success" << std::endl;
    }else {
        std::cout << "failed" << std::endl;
    }
    delete db;
    return 0;
}

我使用g++ main.cpp -lleveldb -lsnappy -o test编译我的代码。编译器生成错误,如:

Undefined symbols for architecture x86_64:
  "leveldb::DB::Open(leveldb::Options const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, leveldb::DB**)", referenced from:
      _main in ccYcksfh.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

如何解决此链接错误?

1 个答案:

答案 0 :(得分:0)

您可以使用编译器版本安装leveldb。

{
      "port": "3003",
      "mongoURI": "mongodb://localhost:27017/serviceRequest",
      "MQ": "RMQ",
      "logLevel": "2",
      "version": "1.1",
      "created": "03-06-2018 03:11:00 PM",
      "active": "N"
    }

Can't link against leveldb on OSX