- Introduction to oracle Pro * C
- Install the Oracle client
- Install sqlpus
- Install Pro * C
Oracle's Pro * C has been very popular. Although it is not highly respected, it is still used in mature projects, so it makes sense to build your own pro * C compiling environment. If you search for the Pro * C compiling environment in Windows, you may still find the environment in Linux. However, there is basically no such environment in Linux. Of course, if you are willing to chew on e files, there may be some problems, however, most of them can only obtain the required pro * C compiling environment by introducing the installation of Oracle 9i. If you just want to install Pro * C, that is none, that's why I want to write it down and record it.
Installing iise 9i in Linux is very troublesome. First of all, according to the official statement, Oracle only supports Red Hat. Although most servers are used, I want to be a developer, certainly, the release versions are varied. In general, installing Oracle9i in Ubuntu has the following troubles: 1. patch is required, and the patch is also difficult; 2. chinese characters are not supported during installation; 3. to install this giant object for this function; 4. it is difficult to find some very old versions of dynamic link libraries; 5. the installation disc of oracle9i is really hard to get; 6. installation takes a long time.
First, download the file from the Oracle website. The address below is http://www.oracle.com/policy/software/tech/oci/instantclient/htdocs/linuxsoft.html. We mainly want to install these, Oracle thin client, sqlplus and Pro * C. .
Now you have installed the Oracle thin client and sqlplus. First, create a directory and decompress the file as follows:
$ CD/OPT
$ Sudo mkdir Oracle
$ Unzip instantclient-basic-linux32-11.1.0.7.zip
$ Unzip instantclient-sqlplus-linux32-11.1.0.7.zip
Edit the. bash_profile environment variables in the main directory.
Export ORACLE_HOME = $ oracle_base/instantclient_11_1
Export LD_LIBRARY_PATH = $ ORACLE_HOME: $ {LD_LIBRARY_PATH}
Export Path = $ ORACLE_HOME: $ ORACLE_HOME/SDK: $ path
Export nls_lang = american_america.utf8
Copy the service name tnsnames. ora to the corresponding path, for example,/opt/Oracle/instantclient_11_1/Network/admin.
Load Environment Variables
$ .~ /. Bash_profile
Install the AIO library and add the Oracle path to lD. conf.
$ Sudo apt-Get install libaio1
$ Sudo VI/etc/lD. So. conf. d/ora. conf
/Opt/Oracle/instantclient_11_1/
Update
$ Ldconfig-V
Yes.
$ Sqlplus user @ SERVICE_NAME/Password
Now, install Pro * C.
Decompress instantclient-precomp-linux32-11.1.0.7.zip to $ ORACLE_HOME
Create a subdirectory precomp/admin in the directory, move pcscfg. cfg to the directory, and edit the header file location.
Sys_include = (/opt/Oracle/instantclient_11_1/SDK/include,/usr/include,/usr/include/Linux)
Ltype = short
Create a subdirectory lib
$ Sudo mkdir lib
$ CD lib
$ Sudo ln-s libclntsh. So/opt/Oracle/instantclient_11_1/libclntsh. so.11.1
Write a helloworld command to verify whether our Pro * C can be used ..
# Include < Stdio. h >
# Include < Stdlib. h >
Exec SQL include sqlca;
Exec SQL include region;
Exec Oracle option (region = Yes );
Exec SQL begin declare section;
Varchar v_username [ 20 ];
Varchar v_password [ 20 ];
Exec SQL end declare section;
Void Sqlerror ();
Int Main () {
V_username.len = Sprintf (v_username.arr, " Tpibs @ ywdev " );
V_password.len = Sprintf (v_password.arr, " Tppw123 " );
Exec SQL whenever sqlerror do sqlerror ();
Exec SQL CONNECT: v_username identified by: v_password;
Printf ( " \ Nconn Oracle, user: % s \ n " , V_username.arr );
Exec SQL commit work release;
Return 0 ;
}
Void Sqlerror () {
Exec SQL whenever sqlerror continue;
Printf ("\ Noracle error detected: \ n");
Printf ("\ N %. 70s \ n", Sqlca. sqlerrm. sqlerrmc );
Exec SQL rollback release;
}
Write a simple makefile.
Target = Hello
SRCS = Main . C
Objs = Main . O
Commlib = - Lpthread - Lclntsh
Linker = $ (Cc)
Rm = / Bin / Rm - F
Proc = Proc
Procflags = Code = Ansi_c ireclen = 2048 Oreclen = 2048 Parse = None include =/ USR / Include \
Include =/ USR / Include / Linux \
Include =/ USR / Local / Include \
Include =/ USR / Lib / Gcc / Iworkflow - Linux - GNU / 4.3 . 3 / Include
Cflags = - I $ (ORACLE_HOME) / Precomp / Public \
- L $ (ORACLE_HOME) / Lib
. Suffixes : . O . C . PC
. C . O :
$ (Cc) - C $ (cflags) $ <
. PC . C :
@ Echo " Proc. "
- $ (Proc) INAME = $ *. PC $ (procflags)
$ (Target) : $ (SRCS) $ (objs)
$ (Cc) - O $ @ $ (objs) $ (cflags) $ (commlib)
Clean :
$ (RM) $ (target) $ (objs) $ (Target : % = %. C)
$ Make
$ ./ Hello
conn Oracle , User : tpibs @ ywdev