User forums > Using Code::Blocks
-lclsntsh, -lnnz11, -locci not found in c++ conection with oracle programm
Rahul:
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
--- 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;
}
--- End code ---
is shows following errors :-
--- Code: ----------------- 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))
--- End code ---
i added these libs in project->build options -> linker settings. and in search directories
i added following
--- Code: ---/usr/include/oracle/11.2/client64
/opt/oracle/instantclient_11_2/sdk/include
--- End code ---
also i added LD_LIBRTARY_PATH env variables as :
--- Code: ---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
--- End code ---
sodev:
You need to add the paths to the libraries to the search directories of the linker.
Rahul:
i added in LD_LIBRARY_PATH as LD_LIBRARY_PATH=/opt/oracle/instantclient_11_2:/usr/lib/oracle/11.2/client64/lib:/usr/local/lib:/usr/lib:/usr/local/lib64:/usr/lib64:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH . but not getting solution
sodev:
LD_LIBRARY_PATH doesnt help you during compile time, it might be required during runtime if your ldconfig isnt configured properly.
Gcc doesnt care about this variable during compiling, you have to specify the search paths for the libraries like you have to specify the include paths.
Rahul:
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:
--- Code: ---./oraconn: error while loading shared libraries: libclntsh.so.11.1: cannot open shared object file: No such file or directory
--- End code ---
Navigation
[0] Message Index
[#] Next page
Go to full version