继续上篇文章的讲述,让我们一块走进神奇的oci。
ORACLE调用接口(Oracle Call Interface简称OCI)提供了一组可对ORACLE数据库进行存取的接口子例程(函数),通过在第三代程序设计语言(如C语言)中进行调用可达到存取ORACLE数据库的目的。
在普通的情况下,用户可以通过SQL和PL/SQL来访问数据库中的数据。ORACLE调用接口ORACLE数据库除了提供SQL和PL/SQL来访问数据库外,还提供了一个第三代程序设计语言的接口,用户可以通过C、COBOL、FORTRAN等第三代语言来编程访问数据库。OCI就是为了实现高级语言访问数据库而提供的接口。OCI允许开发者在程序里使用SQL和PL/SQL来访问数据库。开发者可以使用第三代语言来编写程序,而使用OCI来访问数据库。
OCI是由一组应用程序开发接口(API)组成的,ORACLE提供API的方式是提供一组库。这组库包含一系列的函数调用。这组函数包含了连接数据库、调用SQL和事务控制等。在安装DBMS SERVER或者客户端的时候,就安装了OCI。
occidemo.sql、occidml.cpp
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
[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 -lclntsh collect2: ld returned 1 exit status
-lclntsh 指连接lib文件libclntsh.so -locci 指连接lib文件libocci.so Oracle客户端的lib包为:libclntsh.so.10.1、libocci.so.10.1
cp libclntsh.so.10.1 libclntsh.so cp libocci.so.10.1 libocci.so
或者:warning: libstdc++.so.5, needed by /home/oracle/OraHome1/lib/libocci.so, may conflict with libstdc++.so.6
Oracle10.2.0.4的会依赖与低版本的标准C++库libstdc++.so.5
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 个人认为,方案4会更好一些。 方案2在尝试中,根据调查,最好不要在一个程序中同时依赖 libstdc++.so.5和libstdc++.so.6。
http://www.itpub.net/thread-465101-1-1.html
undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::s ize() 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
g++ HelloWorld.cpp -o HelloWorld (用g++, 效果是一样的, stdc++会被自动连接)
http://hi.baidu.com/kzsoft/blog/item/a507ca182fbdf10135fa41a4.html http://www.cppblog.com/soak/
原文地址:http://blog.csdn.net/san1156/article/details/43308457