[unixODBC-support] Program works from commandline but not from codeblocks IDE
Ken Resander
kresander at yahoo.com
Mon May 25 13:45:48 BST 2009
Nick,
I asked for your assistance before to connect to Oracle Express and you suggested I run strace. That eventually solved the problem. Many thanks for that!
The problem was that Oracle had changed the install directory structure (undocumented?). I discovered by trial and error that ORACLE_HOME has to be:
ORACLE_HOME = /usr/lib/oracle/xe/app/oracle/product/10.2.0/server
not
ORACLE_HOME = /usr/lib/oracle/xe/app/oracle/product/10.2.0
which is indicated in dozens of pages on the Internet going back many years.
I am using code::blocks IDE for programming on Ubuntu/Linux. It is a good IDE and it has served me well. I have ported several 100+ file projects from Windows and my current project developed on codeblocks connects to DB2, MySQL, Mimer SQL and SQL Anywhere via unixODBC, but Oracle is still giving me a problem. The Oracle connect works from the command line but not from codeblocks.
I have posted about this on the codeblocks General forum, but not received any responses that have helped. The section below is taken from that forum.
++++ post on codeblocks forum begin +++
For Ubuntu 8.10. using codeblocks rev 5607 (the latest).
The program connects ok via ODBC to Oracle Express on the Ubuntu commandline:
ken at ken-desktop:~/projects/lsken/bin/Debug$ ./lsken2
ODBC connected OK << my tracemessage
but not from codeblocks Run in Build menu or Start on Debug menu. I receive error:
Can't open lib /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/lib/libsqora.so.10.1
The so file is the Oracle ODBC driver and the unixODBC driver manager outputs the message.
I have written a minimal test program (THISAPP) in main.cpp that shows the problem:
#include <stdio.h>
#include <string.h>
#include "sql.h"
#include "sqlext.h"
static void dspmessage ( const char * title , const char * msg )
{
printf ( "%s: %s " , title , msg ) ;
printf ( "Press Return/Enter to continue\n" ) ;
getchar ( ) ; //to wait
}
static void sqlerrinfo ( int handletp , int handle , const char * logstring )
{
char txt [ 4002 ] ;
int maxlen = 4000 ;
int ofs = sprintf ( txt , "%s\n" , logstring ) ;
int recnbr = 1;
long nerr ;
short lenerrmsg ;
int ln ;
unsigned char state [ 12 ] = { 0 } ;
unsigned char msg [ SQL_MAX_MESSAGE_LENGTH+1 ] = { 0 } ;
char line [ 802 ] = { 0 } ;
int rc = SQL_SUCCESS ;
while ( rc != SQL_NO_DATA_FOUND)
{
rc = SQLGetDiagRec ( handletp , (SQLHANDLE)handle , recnbr ,
state, &nerr , msg , SQL_MAX_MESSAGE_LENGTH ,
&lenerrmsg ) ;
ln = sprintf ( line , "%d: st=%s, nerr=%d, msg=\n%s\n" ,
recnbr , state , (int)nerr , msg ) ;
if ( ln+ofs < maxlen )
{
strcpy ( txt+ofs , line ) ;
ofs += ln ;
}
else
{
break ;
} ;
recnbr++; // for next diagnostic record.
}
dspmessage ( "usage error" , txt ) ;
}
static bool success ( SQLRETURN rc )
{
return (rc == SQL_SUCCESS) || (rc == SQL_SUCCESS_WITH_INFO) ;
}
static bool connectSrv ( const char * dsn , const char * uid , const char * pwd )
{
SQLHENV henv;
SQLRETURN rc = SQLAllocHandle ( SQL_HANDLE_ENV , SQL_NULL_HANDLE , &henv ) ;
if ( !success ( rc ) )
{
dspmessage ( "sqlapi" , "SQLAllocHandle Env failed" ) ;
return false ;
}
rc = SQLSetEnvAttr ( henv, SQL_ATTR_ODBC_VERSION , (void*)SQL_OV_ODBC3 , 0 ) ;
if ( !success ( rc ) )
{
sqlerrinfo ( SQL_HANDLE_ENV , (int)henv , "Set ODBC version fail" ) ;
SQLFreeEnv ( henv ) ;
return false ;
} ;
SQLHDBC hdbc;
rc = SQLAllocHandle ( SQL_HANDLE_DBC , henv , &hdbc ) ;
if ( !success ( rc ) )
{
sqlerrinfo ( SQL_HANDLE_ENV , (int)hdbc , "Alloc connection handle error" ) ;
SQLFreeEnv ( henv ) ;
return false ;
} ;
SQLSetConnectAttr ( hdbc , SQL_LOGIN_TIMEOUT , (void*)5 , 0 ) ;
char msg [ 100 ] ;
rc = SQLConnect ( hdbc , (SQLCHAR*)dsn , SQL_NTS,
(SQLCHAR*) uid , SQL_NTS,
(SQLCHAR*) pwd , SQL_NTS);
if ( !success ( rc ) )
{
sprintf ( msg , "SQLConn: dsn=%s user=%s pwd=%s\n" , dsn , uid , pwd ) ;
sqlerrinfo ( SQL_HANDLE_DBC , (int)hdbc , msg ) ;
SQLFreeConnect ( hdbc ) ;
SQLFreeEnv ( henv ) ;
dspmessage ( "sqlapi" , "SQLConnect failed" ) ;
return false ;
} ;
SQLHSTMT hstmt;
rc = SQLAllocHandle ( SQL_HANDLE_STMT , hdbc , &hstmt);
if ( !success ( rc ) )
{
sqlerrinfo ( SQL_HANDLE_DBC , (int)hdbc , "Alloc Stmt error" ) ;
SQLDisconnect ( hdbc ) ;
SQLFreeConnect ( hdbc ) ;
SQLFreeEnv ( henv ) ;
return false ;
} ;
return true ;
}
int main ( int argc , char * argv[] )
{
if ( connectSrv ( "TestDBDSN" , "hr" , "hr" ) )
{
dspmessage ( "sqlapi" , "ODBC Connect OK\n" ) ;
}
return 0 ;
}
I am using unixODBC 2.2.11-16build2 available via Synaptic package Manager in Ubuntu 8.10. The sql header files are from the Include directory of unixODBC. The unixODBC driver manager is in usr/lib/libodbc.so.1 and is linked using local linker settings section in codeblocks. There are no global linker settings.
The oracle ODBC driver is in /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/lib/libsqora.so.10.1
I have added the following to the Ubuntu startup script:
ODBCINI=/etc/odbc.ini
export ODBCINI
ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
export ORACLE_HOME
TNS_ADMIN=$ORACLE_HOME/network/admin
export TNS_ADMIN
LD_LIBRARY_PATH=/usr/lib:/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/lib
export LD_LIBRARY_PATH
Earlier I had exactly the same error when I had set the LD_LIBRARY_PATH incorrectly, but it is correct now. Is there any possibility of codeblocks disturbing the LD_LIBRARY_PATH value? OR is there anything that I may have done wrong when setting up the project that might cause this?
To summarise:
THISAPP + unixODBC in Debug mode OK on commandline
THISAPP + unixODBC in Release mode OK on commandline
THISAPP + unixODBC + CodeBlocks Start in Debug mode fails to load the Oracle ODBC
driver
THISAPP + unixODBC + CodeBlocks Run in Release mode fails to load the Oracle ODBC driver
What else can I do to try to pinpoint the problem?
+++ codeblocks forum post end +++++
This seems to be a codeblocks problem. Is there anything I can do to demonstrate that? or can you think of anything that might cause this?
Suggestions most welcome.
Ken
New Email names for you!
Get the Email name you've always wanted on the new @ymail and @rocketmail.
Hurry before someone else does!
http://mail.promotions.yahoo.com/newdomains/aa/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.unixodbc.org/pipermail/unixodbc-support/attachments/20090525/b7946192/attachment.html>
More information about the unixODBC-support
mailing list