i've centos 6.4 as server and centos7.5 as client both in VM. I am trying to connect
oracle 11gr2 with c++ using codeblocks. following is code
#include <iostream>
#include <oracle/11.2/client64/occi.h>
#include <iomanip>
using namespace oracle::occi;
using namespace std;
int main()
{
const string user="rahul", passwd = "rahul", connstring = "orcl";
Environment *env = Environment::createEnvironment();
Connection *conn = env->createConnection(user, passwd, connstring);
string strstmt = "select *from emp";
Statement *stmt = conn->createStatement(strstmt);
ResultSet *rs = stmt->executeQuery();
while(rs->next())
{
cout << setw(4) << rs->getInt(1) <<" "<< setw(6) << rs->getString(2) << " "
<< setw(7) << rs->getString(3)<<" "<<setw(4)<< rs->getInt(4) << setw(9)<<" "
<< rs->getString(5)<< " "<< setw(4) << rs->getInt(6) << " " << setw(4)<< rs->getInt(7)<<" "
<< setw(5) << rs->getInt(8)<<endl;
}
stmt->closeResultSet(rs);
conn->terminateStatement(stmt);
env->terminateConnection(conn);
Environment::terminateEnvironment(env);
return 0;
}
is shows following errors :-
-------------- Build: Debug in oraconn (compiler: GNU GCC Compiler)---------------
g++ -o bin/Debug/oraconn obj/Debug/main.o -lclntsh -lnnz11 -locci
/usr/bin/ld: cannot find -lclntsh
/usr/bin/ld: cannot find -lnnz11
/usr/bin/ld: cannot find -locci
collect2: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
4 error(s), 0 warning(s) (0 minute(s), 0 second(s))
i added these libs in project->build options -> linker settings. and in search directories
i added following
/usr/include/oracle/11.2/client64
/opt/oracle/instantclient_11_2/sdk/include
also i added LD_LIBRTARY_PATH env variables as :
LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib:/usr/local/lib:/usr/lib:/usr/local/lib64:/usr/lib64:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH
PATH=$PATH:/opt/oracle/instantclient_11_2; export PATH
TNS_ADMIN=/opt/oracle/instantclient_11_2/network/admin; export TNS_ADMIN
CLASSPATH=/opt/oracle/instantclient_11_2:/usr/lib/oracle/11.2/client64/lib:$CLASSPATH; export CLASSPATH
ORACLE_HOME=/opt/oracle/instantclient_11_2; export ORACLE_HOME
INCLUDEPATH=/opt/oracle/instantclient_11_2/sdk/inclcue:$INCLUDEPATH; export INCLUDEPATH
i added this "/usr/lib/oracle/11.2/client64/lib" for search directories-> linker and "/opt/instantclient_11_2/sdk/include" for compiler
it compiles correctly but when I run this "oraconn" in terminal it gives this error:
./oraconn: error while loading shared libraries: libclntsh.so.11.1: cannot open shared object file: No such file or directory
yes this file exists :-
[root@client64ora11gr2 instantclient_11_2]# ll /usr/lib/oracle/11.2/client64/lib/libclntsh.so
lrwxrwxrwx. 1 root root 17 Dec 5 16:14 /usr/lib/oracle/11.2/client64/lib/libclntsh.so -> libclntsh.so.11.1
[root@client64ora11gr2 instantclient_11_2]# ll /usr/lib/oracle/11.2/client64/lib/libclntsh.so.11.1
-rw-r--r--. 1 root root 53865194 Aug 24 2013 /usr/lib/oracle/11.2/client64/lib/libclntsh.so.11.1
also asecond problem arises when i ran these commands:
# chown -R rahul:rahul /opt/instantclient_11_2/
and
# chmod -R 775 /opt/instantclient_11_2/
after that when i ran sqlplus:
# sqlplus scott/tiger@orcl
Segmentation fault (core dumped)
what should about this.