Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7185577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:26:47+00:00 2026-05-28T18:26:47+00:00

I try to write a wrapper class for leveldb. Basically the part of the

  • 0

I try to write a wrapper class for leveldb. Basically the part of the header file which generates my problem is (CLevelDBStore.h🙂

#include "leveldb/db.h"
#include "leveldb/comparator.h"

using namespace leveldb;
class CLevelDBStore {

    public:
        CLevelDBStore(const char* dbFileName);
        virtual              ~CLevelDBStore();

        /* more stuff */ 67 private:

    private:
        CLevelDBStore();
        static               leveldb::DB* ldb_;
};

The corresponding code in the CLevelDBStore.cpp file is:

#include "CLevelDBStore.h"
DB* CLevelDBStore::ldb_;

CLevelDBStore::CLevelDBStore(const char* dbFileName) {
    Options options;
    options.create_if_missing = true;

    DB::Open((const Options&)options, (const std::string&) dbFileName, (DB**)&ldb_);
    Status status = DB::Open(options, dbFileName);
}

I now try to compile my test file (test.cpp), which basically is

#include "leveldb/db.h"
#include "leveldb/comparator.h"
#include "CLevelDBStore.h"

int main() {
    std::cout << "does not compile" << std::endl;
    return 0;
}

Note, I don’t even use the wrapper class yet. It’s just to generate the compilation error.

The compilation

g++ -Wall -O0 -ggdb -c CLevelDBStore.cpp -I/path/to/leveldb/include
g++ -Wall test.cpp -O0 -ggdb -L/path/to/leveldb -I/path/to/leveldb/include \
   -lleveldb -Wall -O2   -lz -lpthread ./CLevelDBStore.o -llog4cxx \
   -o levelDBStoretest

yields

CLevelDBStore.cpp:27: undefined reference to `leveldb::DB::Open(leveldb::Options const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, leveldb::DB**)'

I looked at the leveldb code where leveldb::DB::Open is defined and it turned out to be a static method.

class DB {
    public:
        static Status Open(const Options& options,
                           const std::string& name,
                           DB** dbptr);
    /* much more stuff */
}

Could this somehow generated problemes when linking?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:26:48+00:00Added an answer on May 28, 2026 at 6:26 pm

    I think this is library link order. Try placing -leveldb after CLevelDBStore.o:

    g++ -Wall test.cpp -O0 -ggdb -L/path/to/leveldb -I/path/to/leveldb/include
    -Wall -O2 ./CLevelDBStore.o -lleveldb -lz -lpthread -llog4cxx
    -o levelDBStoretest

    From GCC Options for Linking:

    -llibrary

    Search the library named library when linking. It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, foo.o -lz bar.o' searches libraryz’ after file foo.o but before bar.o. If bar.o refers to functions in `z’, those functions may not be loaded.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to write KSH script for processing a file consisting of name-value pairs,
I try to write to a large file, but it seems like it does
I try to write a site with CodeIgniter but I've a problem with PHP.
I try to write a XML<>Object Mapper for my Entity Framework Code First class.
I try to write a simple client/server application (all application is a bluetooth service
I try to write a simple Markdown parser in JavaScript. Therefore I want to
I try to write a macro in clojure that sets up a namespace and
I try to write a simple user script to enlarge the picture when you
I try to write the following in latex: \begin{itemize} \item \textbf{insert(element|text)} inserts the element
I try to write :ab in Vim for faster coding but the question is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.