Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't build simple program #114

Closed
stephenpmorgan opened this issue Apr 9, 2014 · 9 comments
Closed

Can't build simple program #114

stephenpmorgan opened this issue Apr 9, 2014 · 9 comments

Comments

@stephenpmorgan
Copy link

I must be doing something stupid, but I can't build a simple program with rocksdb. I get a bunch of undefined references from standard functions. Can anyone give me some help? Any help would be appreciated!!

I compile and build with the following commands:
g++ -c -I./include -std=c++11 mytest.cc
g++ -o mytest -L. -lrocksdb mytest.o

The program (mytest.cc) is as follows:

include <assert.h>

include <iostream>

include "rocksdb/db.h"

int
main(int argc, char *argv[])
{
rocksdb::DB *db;
rocksdb::Options options;

options.create_if_missing = true;
options.error_if_exists = true;

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

delete db;

return 0;
}

I get back the following complaints:

mytest.o: In function main':
mytest.cc:(.text+0x11b): undefined reference torocksdb::DB::Open(rocksdb::Options const&, std::string const&, rocksdb::DB**)'
mytest.o: In function rocksdb::Options::Options()':
mytest.cc:(.text._ZN7rocksdb7OptionsC2Ev[_ZN7rocksdb7OptionsC5Ev]+0x15): undefined reference torocksdb::DBOptions::DBOptions()'
mytest.cc:(.text._ZN7rocksdb7OptionsC2Ev[_ZN7rocksdb7OptionsC5Ev]+0x27): undefined reference to `rocksdb::ColumnFamilyOptions::ColumnFamilyOptions()'
collect2: error: ld returned 1 exit status

@igorcanadi
Copy link
Collaborator

Hmm looking. How did you build rocksdb? make shared_lib?

@stephenpmorgan
Copy link
Author

just "make"

@igorcanadi
Copy link
Collaborator

Hey, I just tried the same thing and it works for me:

icanadi@icanadi-mbp1 rocksdb $ g++ -c -I./include -std=c++11 mytest.cc
icanadi@icanadi-mbp1 rocksdb $ g++ -o mytest -L. -lrocksdb mytest.o -lbz2 -lz -lsnappy
icanadi@icanadi-mbp1 rocksdb $ ./mytest

Can you please try make clean; make?

@stephenpmorgan
Copy link
Author

I just tried again after "make clean; make" and got the same results (the build didn't work in the same way). I guess my environment must be screwed up (but how?). I'm building with g++ 4.7.2 on ubuntu 12.10. Do I need g++ 4.8?

@igorcanadi
Copy link
Collaborator

You shouldn't need g++ 4.8.

Can you try:

  1. building with 2.8 release? (branch 2.8.fb)
  2. linking with shared library (you can make it with make shared_lib)

@igorcanadi
Copy link
Collaborator

Let me try the same thing on ubuntu 12.10

@igorcanadi
Copy link
Collaborator

Reproed the issue on ubuntu 12.10. Looking

@igorcanadi
Copy link
Collaborator

It looks like you have to specify library after your .o file. So your second command should be:

g++ -o mytest mytest.o -L. -lrocksdb -lsnappy -lpthread -lbz2 -lz -lrt

(also added other libraries you need to link with)

@stephenpmorgan
Copy link
Author

You're right--that works for me. Sorry for the bother.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants