Author Topic: -lclsntsh, -lnnz11, -locci not found in c++ conection with oracle programm  (Read 1039 times)

Offline Rahul

  • Multiple posting newcomer
  • *
  • Posts: 15
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: [Select]
#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 :-
Code: [Select]
-------------- 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
Code: [Select]
/usr/include/oracle/11.2/client64
/opt/oracle/instantclient_11_2/sdk/include

also i added LD_LIBRTARY_PATH env variables as :
Code: [Select]
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

Offline sodev

  • Regular
  • ***
  • Posts: 314
You need to add the paths to the libraries to the search directories of the linker.

Offline Rahul

  • Multiple posting newcomer
  • *
  • Posts: 15
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

Offline sodev

  • Regular
  • ***
  • Posts: 314
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.

Offline Rahul

  • Multiple posting newcomer
  • *
  • Posts: 15
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: [Select]
./oraconn: error while loading shared libraries: libclntsh.so.11.1: cannot open shared object file: No such file or directory

Offline sodev

  • Regular
  • ***
  • Posts: 314
Does that file exist? Is it in one of the paths your ldconfig specifies? Is it in one of the paths your LD_LIBRARY_PATH specifies? Does it have the correct architecture?

Offline Rahul

  • Multiple posting newcomer
  • *
  • Posts: 15
yes this file exists :-
Code: [Select]
[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:
Code: [Select]
# chown -R rahul:rahul /opt/instantclient_11_2/and
Code: [Select]
# chmod -R 775 /opt/instantclient_11_2/
after that when i ran sqlplus:
Code: [Select]
# sqlplus scott/tiger@orcl
Segmentation fault (core dumped)
what should about this.
« Last Edit: January 19, 2019, 07:39:13 am by Rahul »