LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Berkeley DB (Which Lib to link?) (http://www.linuxquestions.org/questions/programming-9/berkeley-db-which-lib-to-link-418561/)

lucky6969b 02-22-2006 08:51 PM

Berkeley DB (Which Lib to link?)
 
I've been searching in all directories. It isn't prominent to find
which library files I have to pass to the Linker.
g++ -o db db_try.cpp -l?????

Please fill in the question marks.
Thanks
Jack

xhi 02-22-2006 08:58 PM

you probably have to go with somthing like

-ldb-XXXX
or
-ldbXXXX

where XXXX is the version of bdb you want to link to so if its 4 then

-ldb4 or -ldb-4

hth

lucky6969b 02-22-2006 09:42 PM

Tried both. It said the files weren't found.
Thanks Anyway
Jack

lucky6969b 02-22-2006 09:51 PM

I mean the lib files
Thanks
Jack

lucky6969b 02-22-2006 10:15 PM

Now, I finally got thru the compiler. Now facing the linker again
Seems like even the Db::Db(...) isn't correctly linked.
g++ -o try db_try.cpp -ldb

I've got errors such as Db::set_error_stream undefined reference etc
Why? it should be linked correctly...
Thanks
Jack

xhi 02-22-2006 10:58 PM

maybe the db libs are in ld's path..

find where they are on your system and try to pass the -L option to gcc

ex
g++ -L/path/to/libs -ldb4 file.cpp

also are you sure you should be linking against db4 and not db3*.. ?

lucky6969b 02-22-2006 11:29 PM

Here is a dump

[root@localhost dbtest]# g++ -L/usr/lib -o try db.cpp -ldb4
In file included from /usr/lib/gcc/i386-redhat-linux/4.0.0/../../../../include/c++/4.0.0/backward/iostream.h:31,
from db.cpp:1:
/usr/lib/gcc/i386-redhat-linux/4.0.0/../../../../include/c++/4.0.0/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
/usr/bin/ld: cannot find -ldb4
collect2: ld returned 1 exit status
[root@localhost dbtest]# g++ -L/usr/lib -o try db.cpp -ldb
In file included from /usr/lib/gcc/i386-redhat-linux/4.0.0/../../../../include/c++/4.0.0/backward/iostream.h:31,
from db.cpp:1:
/usr/lib/gcc/i386-redhat-linux/4.0.0/../../../../include/c++/4.0.0/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
/tmp/ccSBUnso.o(.text+0x49f): In function `MyDb::MyDb(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, bool)':
db.cpp: undefined reference to `Db::Db(DbEnv*, unsigned int)'
/tmp/ccSBUnso.o(.text+0x4d5):db.cpp: undefined reference to `Db::set_error_stream(std::basic_ostream<char, std::char_traits<char> >*)'
/tmp/ccSBUnso.o(.text+0x4ec):db.cpp: undefined reference to `Db::set_flags(unsigned int)'
/tmp/ccSBUnso.o(.text+0x522):db.cpp: undefined reference to `Db::open(DbTxn*, char const*, char const*, DBTYPE, unsigned int, int)'
/tmp/ccSBUnso.o(.text+0x6b5):db.cpp: undefined reference to `Db::~Db()'
/tmp/ccSBUnso.o(.text+0x6e9): In function `MyDb::MyDb(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, bool)':
db.cpp: undefined reference to `Db::Db(DbEnv*, unsigned int)'
/tmp/ccSBUnso.o(.text+0x71f):db.cpp: undefined reference to `Db::set_error_stream(std::basic_ostream<char, std::char_traits<char> >*)'
/tmp/ccSBUnso.o(.text+0x736):db.cpp: undefined reference to `Db::set_flags(unsigned int)'
/tmp/ccSBUnso.o(.text+0x76c):db.cpp: undefined reference to `Db::open(DbTxn*, char const*, char const*, DBTYPE, unsigned int, int)'
/tmp/ccSBUnso.o(.text+0x8ff):db.cpp: undefined reference to `Db::~Db()'
/tmp/ccSBUnso.o(.text+0x941): In function `__tcf_1':
db.cpp: undefined reference to `Db::~Db()'
/tmp/ccSBUnso.o(.text+0x9a8): In function `__static_initialization_and_destruction_0(int, int)':
db.cpp: undefined reference to `Db::Db(DbEnv*, unsigned int)'
/tmp/ccSBUnso.o(.gcc_except_table+0x68): undefined reference to `typeinfo for DbException'
/tmp/ccSBUnso.o(.gcc_except_table+0x9c): undefined reference to `typeinfo for DbException'
collect2: ld returned 1 exit status

Thanks xhi and other guys
Jack

xhi 02-23-2006 12:04 AM

yeh.
how about if the code is small enough to post ill try to compile on mine and see what needs to be linked..

lucky6969b 02-23-2006 01:21 AM

#include <iostream.h>
#include <string>
#include <db_cxx.h>


Db db(NULL, 0);

u_int32_t oFlags = DB_CREATE;

class MyDb
{
public:
MyDb (std::string& path, std::string& dbName, bool isSecondary);
~MyDb() { close(); }

inline Db &getDb() { return db_; }

private:
Db db_;
std::string dbFileName_;
u_int32_t cFlags_;

MyDb() : db_(NULL, 0) { }

void close();
};

MyDb::MyDb (std::string &path, std::string &dbName,
bool isSecondary)
: db_(NULL, 0),
dbFileName_ (path + dbName),
cFlags_ (DB_CREATE)
{
try
{
db_.set_error_stream (&std::cerr);

if (isSecondary)
db_.set_flags (DB_DUPSORT);

db_.open(NULL, dbFileName_.c_str(), NULL, DB_BTREE, cFlags_, 0);
}
catch (DbException &e)
{
std::cerr << "Error opening database: " << dbFileName_ << "\n";
std::cerr << e.what() << std::endl;
}
catch (std::exception &e)
{
std::cerr << "Error opening database: " << dbFileName_ << "\n";
std::cerr << e.what() << std::endl;
}
}





class Plumedata
{
private:
float m_CO;
float m_NOX;
float m_HC;
float m_CO2;
size_t bufLen_;
char databuf_[500];
public:
inline void setCO(float co) { m_CO = co; }
inline void setNOX(float nox) { m_NOX = nox; }
inline void setHC (float hc) { m_HC = hc; }
inline void setCO2 (float co2) { m_CO2 = co2; }

inline float& getCO() { return m_CO; }
inline float& getNOX() { return m_NOX; }
inline float& getHC() { return m_HC; }
inline float& getCO2() { return m_CO2; }
Plumedata() { clear(); }
Plumedata(void *buffer);


void clear();
char *getBuffer();
void show();
};

//void loadPlumeDB( MyDb &, std::string&);

using namespace std;


void Plumedata::clear()
{
m_CO = 0.0;
m_NOX = 0.0;
m_HC = 0.0;
m_CO2 = 0.0;
}

Plumedata::Plumedata(void *buffer)
{
char *buf = (char *)buffer;


m_CO = *((float *)buf);
bufLen_ = sizeof(float);

m_NOX = *((float *)buf);
bufLen_ += sizeof(float);

m_HC = *((float *)buf);
bufLen_ += sizeof(float);

m_CO2 = *((float *)buf);
bufLen_ += sizeof(float);
}

char *Plumedata::getBuffer(void)
{
memset( databuf_ ,0, 500 );
bufLen_ = 0;
int dataLen = 0;

dataLen = sizeof(float);
memcpy (databuf_, &m_CO, dataLen);
bufLen_ += dataLen;

memcpy (databuf_ + bufLen_, &m_NOX, dataLen);
bufLen_ += dataLen;

memcpy (databuf_ + bufLen_, &m_HC, dataLen);
bufLen_ += dataLen;

memcpy (databuf_ + bufLen_, &m_CO2, dataLen);

return (databuf_);

}

void Plumedata::show()
{
std::cout << "\nCO: " << m_CO << std::endl;
std::cout << "NOX: " << m_NOX << std::endl;
std::cout << "HC: " << m_HC << std::endl;
std::cout << "CO2: " << m_CO2 << std::endl;
}

int main (int argc, char *argv[])
{
std::string basename("./");
std::string databasehome("./");

std::string pDbName("Plumedb.db");






}

lucky6969b 02-23-2006 02:37 AM

There are some examples inside the dir of examples_cxx
Why it's not compiled while on a clean installation?
I saw some files like tag and a folder called getting_started
No exe is found, no makefile
even couldn't compiled using
g++ -o db MyDb.cpp excxx_example_database_read.cpp excxx_example_database_load.cpp -ldb
Could anyone point me right?
Thanks
Jack

xhi 02-23-2006 06:01 PM

i attempted to compile your code and got the linker errors also..

i would suggest downloading bdb and installing it to where you know where everything is at, and attempting to compile the examples from there.. i started the download when i left this morning and was going to try it when i got home.. i had been wanting to mess around with it anyhow..

everything looks like it should work but it just doesnt.. im betting after building the new version it will work.. if i do get it to work ill let you know.. otherwise, good luck.

lucky6969b 02-24-2006 02:32 AM

Someone recommended me to do the following to make the excxx_examples
he told me to go to this dir
build_unix
then type "make excxx_example_database_load"
But still got
unable to infer tagged configuration
Jack

lucky6969b 02-26-2006 08:44 PM

Hi,
Back here. After specifying the absolute path of the lib, I still got the same errors.
I'm building my own project using
g++ -o dbx -D_REENTRANT db.cpp /usr/lib/libdb4-3.a
Thanks
Jack

paulsm4 02-26-2006 09:16 PM

You need two things:

1) the basic Berkeley DB libraries (which is a 'C' API)
... and ...
2) the C++ wrapper

Your link errors all appear to be coming from the C++ wrapper.

On my copy of Suse, you'd need (at minimum) the following two libraries:

Quote:

libdb-4.so
libdb_cxx-4.so

lucky6969b 02-27-2006 01:19 AM

Dear Paul,
I have that file
./root/Desktop/db-4.4.20/build_unix/.libs/libdb_cxx-4.4.so
What should I be doing next?
Thanks
Jack


All times are GMT -5. The time now is 11:25 AM.