本文介绍了g ++找不到标题,但我确实包含它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在编译一个levelDB的小测试:

  code> 

但是如果库不在 / usr / lib 的某个路径中,则可以使用或 / usr / local / lib 你需要

  g ++ -I include -L $ LEVELDB_PATH testLevelDB.cpp -lleveldb 

-L 非常类似于 -I 但它告诉链接器在哪里查找库。



另外,由于您似乎是gcc世界的新手,请查看 gcc介绍文档。


I am starting on c++ and already going wrong ...

I am trying to compile a small test of levelDB :

#include <assert.h>
#include "leveldb/db.h"

using namespace std;

int main() {
  leveldb::DB* db;
  leveldb::Options options;
  options.create_if_missing = true;
  leveldb::Status status = leveldb::DB::Open(options, "/tmp/testdb", &db);
  assert(status.ok());

  return 1;
}

Here is the g++ command :

g++ -I include/ testLevelDB.cpp

Output:

/tmp/ccuBnfE7.o: In function `main':
testLevelDB.cpp:(.text+0x14): undefined reference to `leveldb::Options::Options()'
testLevelDB.cpp:(.text+0x57): undefined reference to `leveldb::DB::Open(leveldb::Options const&, std::string const&, leveldb::DB**)'

The include folder is the one with the levelDB headers.

解决方案

You need to tell the linker to link to the leveldb library such as

g++ -I include/ testLevelDB.cpp -lleveldb

But this won't work if the library is not in /usr/lib or /usr/local/lib for that case assuming the libleveldb.so exists in some path called $LEVELDB_PATH you need to do

g++ -I include -L $LEVELDB_PATH testLevelDB.cpp -lleveldb

-L is much like -I but it tells the linker where to looks for libraries.

Also since you seem to be new to gcc world, please have a look at this gcc intro document.

这篇关于g ++找不到标题,但我确实包含它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 12:00