A Preliminary Study on compilation of oci and a preliminary study on oci

Source: Internet
Author: User

A Preliminary Study on compilation of oci and a preliminary study on oci
0. Preface

Let's continue with the story in the previous article and let us walk into the magical oci.

I. Concepts of oci

ORACLE Call Interface (OCI) provides a set of Interface subroutines (functions) that can be accessed to Oracle databases) to access the ORACLE database.

In normal cases, you can use SQL and PL/SQL to access data in the database. In addition to providing SQL and PL/SQL to access the database, the ORACLE database also provides a third-generation programming language interface, you can use third-generation languages such as C, COBOL, and FORTRAN to program and access the database. OCI is an interface provided to access databases in advanced languages. OCI allows developers to use SQL and PL/SQL in their programs to access the database. Developers can use third-generation languages to write programs and use OCI to access databases.

OCI is composed of a group of Application Development interfaces (APIs). ORACLE provides APIs by providing a group of libraries. This library contains a series of function calls. These functions include connecting to the database, calling SQL, and transaction control. OCI is installed when the dbms server or client is installed.

Ii. oci demo Development
  • In the deployed Oracle client environment, there is an oci demo program under/opt/oracle/sdk/demo:
 occidemo.sql、occidml.cpp
  • The code is simple:
  • Compile statement:
 g++ -I/opt/oracle/sdk/include -I/usr/local/include/boost -L/opt/oracle/lib -o ociTest occidml.cpp -lclntsh -locci /usr/lib/libstdc++.so.5
  • Next we will start compilation and testing.
Iii. Problems Encountered during compilation 1.-lclntsh-locci
  • Problem:-lclntsh-locci
  • Error: undefined reference to 'oracle: occi: Environment: createEnvironment
  • Solution:-lclntsh: This is the dynamic database connecting to oracle. Without this, you cannot connect to oracle.


2. cannot find-lclntsh
  • Problem: cannot find-lclntsh (-lclntsh-locci)
  • Error:
[root@bogon cppTest]# g++ -I/opt/oracle/sdk/include -I/usr/local/include/boost -L/opt/oracle/lib -o ociTest occidml.cpp -lclntsh -locci /usr/lib/libstdc++.so.5/usr/bin/ld: cannot find -lclntshcollect2: ld returned 1 exit status
  • Analysis:
-Lclntsh refers to the lib file libclntsh. so-locci refers to the lib package connecting to the lib file libocci. soOracle client: libclntsh. so.10.1, libocci. so.10.1
  • Solution:
cp libclntsh.so.10.1 libclntsh.socp libocci.so.10.1 libocci.so
3. Oracle and libstdc ++. so
  • Problem: Oracle and libstdc ++. so
  • Error: libstdc ++. so.5, needed by/opt/oracle/lib/libocci. so, not found

Or: warning: libstdc ++. so.5, needed by/home/oracle/OraHome1/lib/libocci. so, may conflict with libstdc ++. so.6

  • Analysis:

Oracle10.2.0.4 depends on the Standard C ++ library libstdc ++. so.5 of earlier versions.

  • Recommended solution:
1) downgrade the oracle to 10.2.0.2.2) Append the libstdc ++. so.5 to package, and use command "cd/usr/lib; ln/opt/webex/imds/lib/so/libstdc ++. so.5.0.7 libstdc ++. so.5 "By this way, when compiling, compiler will report:/usr/bin/ld: warning: libstdc ++. so.5, needed by/home/oracle/OraHome1/lib/libocci. so, may conflict with libstdc ++. so.6 I am still not sure whether will affect the action of program. Need run for a period to test.3) Build all library which imds is using, include TP, WDMS, Jabber decrypt. it is very hard and painful.4) Upgrade oracle to 11 I personally think solution 4 will be better. Solution 2 is trying. According to the investigation, it is better not to depend on libstdc ++. so.5 and libstdc ++. so.6 in a program at the same time.
  • My solution:
  • Reference: http://jimmyleeee.blog.163.com/blog/static/93096182009113035926272/

Http://www.itpub.net/thread-465101-1-1.html


4. Differences between g ++ and gcc
  • Question: What is the difference between g ++ and gcc?
  • Error:
undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const'undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'undefined reference to `std::cout'undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'undefined reference to `std::ios_base::Init::Init()'undefined reference to `std::ios_base::Init::~Init()'collect2: ld returned 1 exit status
  • Solution: gcc HelloWorld. cpp-lstdc ++-o HelloWorld

G ++ HelloWorld. cpp-o HelloWorld (with g ++, the effect is the same, stdc ++ will be automatically connected)

  • Reference: http://blog.sina.com.cn/s/blog_698f90230100y6ir.html
5. cannot restore segment prot after reloc
  • Problem: cannot restore segment prot after reloc
  • Error: libnnz10.so: cannot restore segment prot after reloc
  • Solution: chcon-t texrel_shlib_t/opt/oracle/lib/*. so *
  • Reference: http://blog.csdn.net/qinpeng2000/article/details/6065041

Http://hi.baidu.com/kzsoft/blog/item/a507ca182fbdf10135fa41a4.htmlhttp://www.cppblog.com/soak/

Iv. Reference website
  • More comprehensive summary of errors: http://wenku.baidu.com/view/73fb0ec79ec3d5bbfc0a7405.html
  • Linux system header file and library file search path: http://it.china-b.com/lixt/457143_2.html
From "http: // 192.168.5.252/mediawiki/index. php/% E5 % 88% 9D % E6 % 8E % A2oci % E4 % B9 % 8B % E7 % BC % 96% E8 % AF % 91% E9 % 97% AE % E9 % A2 % 98% e5 % B0 % 8F % E7 % BB % 93--20120605"

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.