g ++找不到标题,但我确实包含它们 [英] g++ can't find headers but I did include them
问题描述
我正在编译一个levelDB的小测试:
#include< assert.h>
#includeleveldb / db.h
using namespace std;
int main(){
leveldb :: DB * db;
leveldb ::选项选项;
options.create_if_missing = true;
leveldb :: Status status = leveldb :: DB :: Open(options,/ tmp / testdb,& db);
assert(status.ok());
返回1;
$ / code>
以下是g ++命令:
g ++ -I include / testLevelDB.cpp
输出:
/tmp/ccuBnfE7.o:函数`main':
testLevelDB.cpp :(。文本+ 0x14):对`leveldb :: Options :: Options()'的未定义引用
testLevelDB.cpp :( .text + 0x57):未定义对`leveldb :: DB :: Open的引用(leveldb :: Options const&;; std :: string const&; leveldb :: DB **)'
是带有levelDB头文件的。
您需要告诉链接器链接到 leveldb
库,例如
g ++ -I include / testLevelDB.cpp -lleveldb
code>
但是如果库不在 / usr / lib $ c $假设libleveldb.so存在于名为
$ LEVELDB_PATH
的某个路径中,则可以使用 / 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 ++找不到标题,但我确实包含它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!