LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-22-2006, 07:51 PM   #1
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Rep: Reputation: 30
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
 
Old 02-22-2006, 07:58 PM   #2
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
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
 
Old 02-22-2006, 08:42 PM   #3
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Original Poster
Rep: Reputation: 30
Tried both. It said the files weren't found.
Thanks Anyway
Jack
 
Old 02-22-2006, 08:51 PM   #4
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Original Poster
Rep: Reputation: 30
I mean the lib files
Thanks
Jack
 
Old 02-22-2006, 09:15 PM   #5
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Original Poster
Rep: Reputation: 30
Now, I finally got thru the compiler. Now facing the linker again
Seems like even the Db:b(...) 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
 
Old 02-22-2006, 09:58 PM   #6
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
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*.. ?
 
Old 02-22-2006, 10:29 PM   #7
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Original Poster
Rep: Reputation: 30
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:b(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:pen(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:b(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:pen(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:b(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
 
Old 02-22-2006, 11:04 PM   #8
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
yeh.
how about if the code is small enough to post ill try to compile on mine and see what needs to be linked..
 
Old 02-23-2006, 12:21 AM   #9
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Original Poster
Rep: Reputation: 30
#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");






}
 
Old 02-23-2006, 01:37 AM   #10
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Original Poster
Rep: Reputation: 30
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
 
Old 02-23-2006, 05:01 PM   #11
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
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.
 
Old 02-24-2006, 01:32 AM   #12
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Original Poster
Rep: Reputation: 30
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
 
Old 02-26-2006, 07:44 PM   #13
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Original Poster
Rep: Reputation: 30
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
 
Old 02-26-2006, 08:16 PM   #14
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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

Last edited by paulsm4; 02-26-2006 at 08:20 PM.
 
Old 02-27-2006, 12:19 AM   #15
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Original Poster
Rep: Reputation: 30
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
/sbin/ldconfig: /usr/lib/libgtkhtml-3.0.so.2 is not a symbolic link rosariowong Slackware 13 04-29-2005 03:41 PM
Berkeley DB aesthete Linux - Software 1 02-12-2005 09:07 AM
symbolic link in /lib alice95089 Linux - Software 1 02-07-2005 08:28 PM
How to link a lib? theonebeyond Programming 3 09-11-2004 03:10 AM
IdConfig: /usr/lib/.... is not a symbolic link. _tomMmy_ Linux - Software 0 08-23-2004 07:12 AM


All times are GMT -5. The time now is 03:22 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration