#include <db_cxx.h>
#include <iostream>
#include <cstdlib>
#include <string>
using std::cout;
using std::endl;
using std::string;
int main(int argc, char *argv[]){
Db db(NULL, 0);
try{
db.open(NULL, "firstdb.db", NULL, DB_BTREE, DB_CREATE, 0);
cout << "The database file has been opend." << endl;
db.close(0);
}
catch(DbException &e){
cout << "Error has occured while creating the database file." << endl;
}
catch(std::exception &e){
cout << "Unknown error has occured." << endl;
}
}
g++ -o first first.cpp出现错误:/tmp/cc24jYcK.o: In function `main':
first.cpp:(.text+0x97): undefined reference to `Db::Db(DbEnv*, unsigned int)'
first.cpp:(.text+0xc5): undefined reference to `Db::open(DbTxn*, char const*, char const*, DBTYPE, unsigned int, int)'
first.cpp:(.text+0xf2): undefined reference to `Db::close(unsigned int)'
first.cpp:(.text+0x1c8): undefined reference to `Db::~Db()'
first.cpp:(.text+0x1e8): undefined reference to `Db::~Db()'
/tmp/cc24jYcK.o:(.gcc_except_table+0x2c): undefined reference to `typeinfo for DbException'
collect2: ld returned 1 exit status
g++ -o first first.cpp -L/usr/local/BerkeleyDB.4.2/lib/也不行.
怎么解决?
#include <iostream>
#include <cstdlib>
#include <string>
using std::cout;
using std::endl;
using std::string;
int main(int argc, char *argv[]){
Db db(NULL, 0);
try{
db.open(NULL, "firstdb.db", NULL, DB_BTREE, DB_CREATE, 0);
cout << "The database file has been opend." << endl;
db.close(0);
}
catch(DbException &e){
cout << "Error has occured while creating the database file." << endl;
}
catch(std::exception &e){
cout << "Unknown error has occured." << endl;
}
}
g++ -o first first.cpp出现错误:/tmp/cc24jYcK.o: In function `main':
first.cpp:(.text+0x97): undefined reference to `Db::Db(DbEnv*, unsigned int)'
first.cpp:(.text+0xc5): undefined reference to `Db::open(DbTxn*, char const*, char const*, DBTYPE, unsigned int, int)'
first.cpp:(.text+0xf2): undefined reference to `Db::close(unsigned int)'
first.cpp:(.text+0x1c8): undefined reference to `Db::~Db()'
first.cpp:(.text+0x1e8): undefined reference to `Db::~Db()'
/tmp/cc24jYcK.o:(.gcc_except_table+0x2c): undefined reference to `typeinfo for DbException'
collect2: ld returned 1 exit status
g++ -o first first.cpp -L/usr/local/BerkeleyDB.4.2/lib/也不行.
怎么解决?