Pro*C Precompiler Hell (merged) [message #440902] |
Wed, 27 January 2010 20:51 |
mjm22
Messages: 54 Registered: January 2010 Location: Singapore
|
Member |
|
|
Well, I have played around with this for ages and can't get it working.
I have a set of c source files MJM.h, MJMmain.c, MJMutils.h and MJMutils.c. I compile them all in a makefile quite nicely. I need to add some database access to the code so I have created a couple of new files... MJMdb.h and MJMdb.pc. At the moment I just have one function in there, to connect to the database (the header and source for these last two files are below)..
#ifndef _MJMDB_H_H
#define _MJMDB_H_H
/* INCLUDE FILES to reference project level defines and types */
#include "MJM.h"
/* FUNCTION PROTOTYPES */
void MJMDBconnect ( MJMstatus_t *pStatus);
#endif
#include <stdio.h>
#include <sqlca.h>
#include "MJM.h"
#include "MJMdb.h"
EXEC SQL INCLUDE sqlca;
void MJMDBconnect( MJMstatus_t *pStatus )
{
EXEC SQL BEGIN DECLARE SECTION;
char *connstr = "USER1/USER1@TESTDB";
EXEC SQL END DECLARE SECTION;
printf("MJMDBconnect: in\n");
*pStatus = MJMFWsuccess_e;
#EXEC SQL WHENEVER SQLERROR GOTO abort;
EXEC SQL WHENEVER SQLWARNING CONTINUE;
EXEC SQL CONNECT :connstr;
printf("MJMDBconnect: out\n");
return;
abort:
printf("MJMDBconnect: abort\n");
*pStatus = MJMFWfail_e;
return;
}
I can't seem to get the MJMdb.h and MJMdb.pc through the precompiler. I can get it pre-compiled if I lump it all in one file (MJMdb.pc) and then run:
proc MJMdb.pc
This produces the MJMdb.c file. I have then tried to include this in the list of source and objects in my C makefile but I get an error stating that sqlca is not defined.
So my questions are (In order of priority):
How do I include the MJM.h file in the 'proc' command?
Any ideas why I get the error on SQLCA, I seem to have included it ok?
Once it is all working, is there a way of adding the Pro*C precompiler commands to the C Makefile?
Thanks in advance,
Mike
|
|
|
|
Re: Pro C Precompiler hell - Simplified version [message #440950 is a reply to message #440918] |
Thu, 28 January 2010 01:28 |
mjm22
Messages: 54 Registered: January 2010 Location: Singapore
|
Member |
|
|
Update...
So i removed the .h file and put everything into the .pc file...
#include <stdio.h>
#include <sqlca.h>
void main()
{
EXEC SQL BEGIN DECLARE SECTION;
char *connstr = "GENEVA_ADMIN/GENEVA_ADMIN@IOTCDBDEV11";
char sys_date[8];
EXEC SQL END DECLARE SECTION;
EXEC SQL WHENEVER SQLWARNING CONTINUE;
EXEC SQL CONNECT :connstr;
EXEC SQL WHENEVER NOTFOUND GOTO notfound;
EXEC SQL SELECT TO_CHAR(SYSDATE, 'YYYYMMDD')
INTO sys_date
FROM DUAL;
found:
printf("System Date is: %s\n", sys_date);
return;
notfound:
printf("Employee record not found in database.\n");
return;
}
I have modified the build instructions as follows.. first pre-compile...
-bash-3.00$ proc test.pc
Pro*C/C++: Release 10.2.0.4.0 - Production on Thu Jan 28 13:52:38 2010
Copyright (c) 1982, 2007, Oracle. All rights reserved.
System default option values taken from: /opt/oracle/product/10.2.0/client_1/precomp/admin/pcscfg.cfg
Then the c compiler...
-bash-3.00$ gcc -o test test.c -I $ORACLE_HOME/precomp/public -L $ORACLE_HOME/lib -lclntsh -lsql10
test.c: In function `main':
test.c:147: warning: return type of 'main' is not `int'
ld: fatal: file /opt/oracle/product/10.2.0/client_1/lib/libclntsh.so: wrong ELF class: ELFCLASS64
ld: fatal: File processing errors. No output written to test
collect2: ld returned 1 exit status
So this has fixed the initial problem. However I now have a new issue. This looks like it is a 32 bit / 64 bit problem. I suspect the answer is to tell Oracle to use the 32 bit libraries? I welcome any help on this new problem.
Regards,
Mike.
|
|
|
|
Re: Pro C Precompiler hell - Simplified version [message #441075 is a reply to message #440960] |
Thu, 28 January 2010 09:09 |
mjm22
Messages: 54 Registered: January 2010 Location: Singapore
|
Member |
|
|
Thanks Vincent.
Yep, that's done it...
proc INAME=test.pc ONAME=test.c
gcc -o test test.c -m64 -I $ORACLE_HOME/precomp/public -L $ORACLE_HOME/lib -lclntsh -lsql10
Everything Compiles ok and the program runs fine. Thanks for the pointer.
Mike
|
|
|