google / google/leveldb

compile error: undefined reference

Open
#710 15 comments 4 reactions 0 assignees View on GitHub
question
Dominant language
C++
Stars
39.4k
Forks
8.2k
PR merge metrics
No merged PRs in 30d

Description

I download and build leveldb according to this [README](https://github.com/google/leveldb), and then properly add `libleveldb.a` and the `include/leveldb` directory (header files) to my environment path.

My test code:

```cpp
/*leveldb_test.cpp
*/

#include
#include
#include
#include

using namespace std;

int main(int argc, char** argv)
{
leveldb::DB* db;
leveldb::Options options;
options.create_if_missing = true;

leveldb::Status status = leveldb::DB::Open(options, "./testdb", &db);
assert(status.ok());

return 0;
}
```

And I compile it as:
```
g++ leveldb_test.cpp -o leveldb_test -lpthread -lleveldb -std=c++11
```
It produces "undefined reference" errors:
```
leveldb_test.o: In function `main':
leveldb_test.cpp:(.text+0x79): undefined reference to `leveldb::DB::Open(leveldb::Options const&, std::__cxx11::basic_string, std::allocator > const&, leveldb::DB**)'
leveldb_test.cpp:(.text+0x29e): undefined reference to `leveldb::Status::ToString[abi:cxx11]() const'
collect2: error: ld returned 1 exit status
```

What is the problem?

My environment: `Linux version 3.10.0-327.el7.x86_64 - gcc version 4.8.3 20140911 - Red Hat 4.8.3-9`

Thanks for any advise.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.