Home » Developer & Programmer » Precompilers, OCI & OCCI » Pro*C Precompiler Hell (merged) (10g2, Solaris 10, gcc)
Pro*C Precompiler Hell (merged) [message #440902] Wed, 27 January 2010 20:51 Go to next message
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
icon8.gif  Pro C Precompiler hell - Simplified version [message #440918 is a reply to message #440902] Wed, 27 January 2010 22:53 Go to previous messageGo to next message
mjm22
Messages: 54
Registered: January 2010
Location: Singapore
Member
Hi,

I have been playing around with my Pro*C source code to simplify it, just to try to get it working. Now I have the following...

test.h file:
#ifndef TEST_H
#define TEST_H

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

void DBconnect();

#endif

test.pc file
#include <stdio.h>
#include <sqlca.h>
#include "test.h"

void DBconnect()
{
    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;
}

To pre-compile, I issue the followiing:
proc INAME=test.pc ONAME=test.c INCLUDE=/opt/oracle/product/10.2.0/client_1/precomp/public
-bash-3.00$ proc INAME=test.pc ONAME=test.c INCLUDE=/opt/oracle/product/10.2.0/client_1/precomp/public

Pro*C/C++: Release 10.2.0.4.0 - Production on Thu Jan 28 11:43:20 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

That works fine and I get the test.c file in my directory.
I then try to compile the .c file, telling it the .h file is in the same directory...
gcc -o test test.c -I.
-bash-3.00$ gcc -o test test.c -I.
test.c:144:19: sqlca.h: No such file or directory
test.c: In function `DBconnect':
test.c:172: error: `sqlca' undeclared (first use in this function)
test.c:172: error: (Each undeclared identifier is reported only once
test.c:172: error: for each function it appears in.)

I have tried this with variants of the INCLUDE option (first not having it and secondly including the filename sqlca.h) but I get the same error.
The /opt/oracle/product/10.2.0/client_1/precomp/public directory is in my path.
Re: Pro C Precompiler hell - Simplified version [message #440950 is a reply to message #440918] Thu, 28 January 2010 01:28 Go to previous messageGo to next message
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 #440960 is a reply to message #440950] Thu, 28 January 2010 01:47 Go to previous messageGo to next message
vicenzo
Messages: 28
Registered: December 2007
Location: Paris
Junior Member
Hi,

if you want to compile in 64bits mode with GCC, use the flag -m64
if you want to link 32bits Oracle libs, link the libs in $ORACLE_HOME/lib32

Regards,

Vincent
Re: Pro C Precompiler hell - Simplified version [message #441075 is a reply to message #440960] Thu, 28 January 2010 09:09 Go to previous message
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
Previous Topic: Oracle OCI: Problem in Query with Date field
Next Topic: PLS-00306: wrong number or types of arguments in call to existing stored procedure (Merged)
Goto Forum:
  


Current Time: Wed Dec 07 03:24:08 CST 2016

Total time taken to generate the page: 0.06522 seconds