I use Clion to make an occi application.My cmakelist.txt:
cmake_minimum_required(VERSION 2.8.4)
project(oracle_manager)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(oracle_manager ${SOURCE_FILES})
INCLUDE_DIRECTORIES(/opt/oracle/product/11.2.0/dbhome_1/rdbms/public)
LINK_DIRECTORIES(/opt/oracle/product/11.2.0/dbhome_1/lib)
SET(REQ_LIB /opt/oracle/product/11.2.0/dbhome_1/lib/libagtsh.so
/opt/oracle/product/11.2.0/dbhome_1/lib/libclntsh.so
/opt/oracle/product/11.2.0/dbhome_1/lib/libocci.so
/opt/oracle/product/11.2.0/dbhome_1/lib/libodm11.so
/opt/oracle/product/11.2.0/dbhome_1/lib/liborasdk.so
/opt/oracle/product/11.2.0/dbhome_1/lib/liborasdkbase.so
/opt/oracle/product/11.2.0/dbhome_1/lib/libsqlplus.so)
TARGET_LINK_LIBRARIES(oracle_manager ${REQ_LIB})
SET(SOURCE_FILES main.cpp)
My program:
int main()
{
Environment* env = Environment::createEnvironment();
Connection* con = env->createConnection("user", "password", "server");
Statement* stmt = con->createStatement("select * from tab");
ResultSet* rs = stmt->executeQuery();
stmt->closeResultSet(rs);
con->terminateStatement(stmt);
env->terminateConnection(con);
Environment::terminateEnvironment(env);
cout << 1 << endl;
return 0;
}
My operating system is ubuntu 12.04 lts and the Oracle database's version is 11g. I compile the main.cpp file use this command "g++ main.cpp -o main.o -locci -lclntsh",build success and run success.Then I use Clion to debug the program.The program is crashed in this line program Environment* env = Environment::createEnvironment();
Is these some wrong in my cmakelist.txt?How to fix it?
Yes,I fix it up!Download the oracle Instant Client zip package from oracle web station:http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html,then extract the package, move libociei.so
to /opt/oracle/product/11.2.0/dbhome_1/lib/
and add /opt/oracle/product/11.2.0/dbhome_1/lib/libociei.so
to MakeList.txt.Build the project and happy debug.