Install the BerkeleyDB database in Fedora

Source: Internet
Author: User
First, go to the Oracle official website to download the Berkeleydb database source file unzip (of course you can also use some visualization tools to decompress), the steps are as follows in the command line Input tar-zxvfdb-5.3.15.t

1. First download the source file of the Berkeley db database from the Oracle official website.

Http://download.oracle.com/otn/berkeley-db/db-5.3.15.tar.gz

2. The downloaded file is a packaged file and needs to be decompressed using tar in the command line (of course you can use some visualization tools to decompress it). The steps are as follows:

Enter tar-zxvf db-5.3.15.tar.gz in the command line

Decompress the package and enter the db-5.3.15 directory with the following files and folders

Enter the build_unix directory

Cd build_unix

Then run ../dist/configure

The configure tool checks the environment and generates the files required to compile the program. After the tool runs successfully, enter

Make

After compilation, you need to run "make install (root permission required)". Then, the library files and required development files will be installed in your system.

The installed files are stored in the/usr/local/BerkeleyDB.5.3 directory of the system by default. To use the files in the programming environment, you need to use them in/etc/ld. so. add/usr/local/BerkeleyDB.5.3/lib to the conf file so that your program can find the library file correctly and finally run the ldconfig command to update your system. Now you can write the database code.

  1. # Include
  2. # Include
  3. # Include
  4. # Define DATABASE "employees. db"
  5. IntMain ()
  6. {
  7. DBT key, data;
  8. DB * dbp;
  9. IntRet;
  10. StructData_struct {
  11. IntEmpid;
  12. CharLastname [50];
  13. CharFirstname [50];
  14. FloatSalary;
  15. } Emp;
  16. Ret = db_create (& dbp, NULL, 0 );
  17. If(Ret! = 0)
  18. {
  19. Perror ("Create");
  20. Return1;
  21. }
  22. Ret = dbp-> open (dbp, NULL, DATABASE, NULL, DB_BTREE, DB_CREATE, 0 );
  23. If(Ret! = 0)
  24. {
  25. Perror ("Open :");
  26. Return1;
  27. }
  28. While(1)
  29. {
  30. Printf ("Enter Employee ID :");
  31. Scanf ("% D", & Emp. empid );
  32. If(Emp. empid = 0)
  33. Break;
  34. Printf ("Enter Last name :");
  35. Scanf ("% S", & Amp; emp. lastname );
  36. Printf ("Enter First name :");
  37. Scanf ("% S", & Emp. firstname );
  38. Printf ("Enter Salary :");
  39. Scanf ("% F", & Emp. salary );
  40. Memset (& key, 0,Sizeof(DBT ));
  41. Memset (& data, 0,Sizeof(DBT ));
  42. Key. data = & (emp. empid );
  43. Key. size =Sizeof(Emp. empid );
  44. Data. data = & emp;
  45. Data. size =Sizeof(Emp );
  46. Ret = dbp-> put (dbp, NULL, & key, & data, DB_NOOVERWRITE );
  47. If(Ret! = 0)
  48. {
  49. Printf ("Employee ID exists \ n");
  50. }
  51. }
  52. Dbp-> close (dbp, 0 );
  53. Return0;
  54. }

Compile code

Gcc-I/usr/local/BerkeleyDB.5.3/include-o newemployee. c-L/usr/local/BerkeleyDB.5.3-ldb

According to the above compilation, an error will occur.

/Usr/bin/ld: cannot find-ldb

Collect2: ld returns 1

Enter the following language in the command line to solve the problem.

Ln-s/usr/local/BerkeleyDB.5.3/lib/libdb. so/usr/lib/libdb. so

Recompile

Gcc-I/usr/local/BerkeleyDB.5.3/include-o newemployee. c-L/usr/local/BerkeleyDB.5.3-ldb

Now, the code is compiled successfully.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.