Configuration of the OCI development library in Linux

Source: Internet
Author: User

The Oracle Calling interface (Oracle call Interface, OCI) provides a set of interface subroutines (functions) that can be accessed from an Oracle database, which can be accessed by invoking a third-generation programming language (such as the C language) for the purpose of accessing the Oracle database.

1. Oracle Client

Because you need to use Ocilib to operate a database deployed on another computer, you need to install an Oracle client; Note that you do not need to download the full Oracle client, download the installation Oracle-instantclient (instant client), the official website is:/http Www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html. There are many types of packages available for download, each of which is divided into. zip and. RPM Two formats, and the ZIP package is equivalent to a free-to-install version after decompression, and the RPM package needs to be installed. The version to be downloaded corresponds to the specific version and number of bits of the database you are connected to, such as the version information of the database that I want to connect to:

11.2. 0.4. 0 -64bit Production

So I chose the 64-bit version of 11.2.0.4.0 to download. The following is a detailed deployment in RPM format package installation configuration.

1) to connect to the Oracle database remotely and to operate the database using Ocilib, you need to download at least the following three packages:

Oracle-instantclient11. 2-basic-11.2. 0.4. 0-1. x86_64.rpm Oracle-instantclient11. 2-devel-11.2. 0.4. 0-1. x86_64.rpm Oracle-instantclient11. 2-sqlplus-11.2. 0.4. 0-1. x86_64.rpm

which

  Basic is the basic package, which is used to run the OCI, OCCI, jdbc-oci applications;

  Sqlplus is a supplemental package/file that is intended to run the Sql*plus instant client;

  devel is equivalent to ORACLE-SDK, contains header files and sample files for the purpose of developing Oracle applications;

The above Sango not less.

The rest of the options are:

Oracle-instantclient11. 2-odbc-11.2. 0.4. 0-1. x86_64.rpm  -Supplemental Packages/ files, additional libraries for running ODBC environments, Oracle-instantclient11.  2-jdbc-11.2. 0.4. 0-1. x86_64.rpm  --complement the XA, international standard, and rowset operations under JDBC;

2) Install using RPM-IVH [package name],

Such as:

RPM-IVH oracle-instantclient11. 2-basic-11.2. 0.4. 0-1. x86_64.rpm

The installed files are placed by default in two locations:

Header file:/usr/include/oracle/11.2/client64/, if you use the times wrong to find the head file, remember to see if the path is this.

Package file:/usr/lib/oracle/11.2/client64/, contains {bin, lib} two folders.

3) Create folder: #mkdir-P/usr/lib/oracle/11.2/client64/network/admin/

4) Create a listening file and add content: #vi/usr/lib/oracle/11.2/client64/network/admin/tnsnames.ora

ORCL =  (DESCRIPTION = (    ADDRESS = (PROTOCOL = TCP) (HOST = 200.31.157.65) (PORT = 1521))    (Connect_data =      (SE RVer = dedicated)      (service_name = *sid*)))  

5) Configure Environment variables

vi ~/. Bashrc# This method controls the permissions that use these environment variables to the user level, that is, for a particular user, if you need to use these environment variables for a user right, you only need to modify the. bashrc file in its personal home directory. Export  oracle_home=/usr/lib/oracle/11.2/client64export  tns_admin= $ORACLE _home/ network/adminexport  Nls_lang='simplified chinese_china'. Zhs16gbkexport  Ld_library_path= $ORACLE _home/lib export  PATH= $ORACLE _home/bin: $PATH

6) make the configured environment variable effective: #source ~/.BASHRC

7) Connect database test: #sqlplus/nolog

2. Installation and Configuration OCI

1): http://vrogier.github.io/ocilib/

2) Configure environment variables: VI ~/.BASHRC

Export Ld_library_path= $LD _library_path:/usr/local/lib

Because the link library path of Oracle has been configured earlier, ld_library_path=:/usr/lib/oracle/11.2/client64/lib before execution;

After executing the above statement, Ld_library_path=:/usr/lib/oracle/11.2/client64/lib:/usr/local/lib;

2) Unzip the Ocilib

tar -xzvf ocilib-4.3. 3-gnu. tar. gz

3) Enter the directory: CD ocilib-4.3.3; then./configure to configure (./configure is used to generate makefile, prepare for the next compilation,--with to specify the header file and library file location required for ocilib)

./configure--with-oracle-lib-path=/usr/lib/oracle/11.2/client64/lib--with-oracle-headers-path=/usr/ include/oracle/11.2/client64

4) Make

Make is used to compile, it reads the instruction from the makefile, and then compiles.

5) make Install

The make install is used for installation, which reads instructions from makefile and installs to the specified location.

3. Example after success

1) Code:

#include"Ocilib.h"#include<stdio.h>intMain () {oci_connection* cn =NULL; if( !oci_initialize (null, NULL, Oci_env_default)) {        return-1; } CN= Oci_connectioncreate ("192.168.1.218:1521/ORCL","HR","HR", Oci_session_default); if(CN! =NULL) {printf ("%s\n", Oci_getversionserver (CN));    Oci_connectionfree (CN);    } oci_cleanup (); return 0;}

2) compiling

gcc ocitest.c-locilib

3) execution

4) Precautions

When you finish installing the demo, it appears:

Because the Ld_library_path is not configured correctly, the dynamic library cannot be found when the a.out is executed, and it is necessary to complete the configuration with reference to the previous steps.

Configuration of the OCI development library in Linux

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.