Re: ESQL/C compilation problems
Posted in 2000
On Wed, 6 Sep 2000, Peter Christmeier wrote:
>Jonathan,
>
>Thanks for the information. I only realized that I forgot some
>important information when I had the quesion submitted. So, let me
>explain my environment:
>
>The following environment variables are set:
>setenv INFORMIXDIR /opt/informix
>setenv PATH /opt/corp/contrib/bin:$INFORMIXDIR/bin:$PATH
>setenv INFORMIXC "CC -N -v">
>The compiler I am using is the HP C++ Compiler Version A.10.40, but the
>program is plain C. Do I still have to use the esql++ script?
I don't know for sure, but probably. Is the C++ compiler operating as a
C compiler or a C++ compiler? If it is operating as a C++ compiler (and
I think it is), then you need to make sure the C code meets the
requirements of a C++ compiler -- specifically, you need to use esql++
to fix the problems in the C code generated by ESQL/C.
>I am compiling the code by typing
>esql ppDump.ec -o ppDump
>
>The esql script contains the following info in its header:
>...
>: Title: esql.sh
>: Sccsid: @(#)esql.sh 9.14 11/11/93 07:43:13
I could expend energy discussing the idiocy of retaining that line in
the esql file, but I've already done so on a number of occasions and
I've yet to achieve anything useful (high blood pressure is not useful).
Suffice to say that the file has been modified more than once since the
75th Anniversary of Armistice Day (the end of World War I).
>I get the ESQL/C version by typing esqlvers, right? That tells me the
>following:
>
>INFORMIX-ESQL Version 9.20.UC2
>Software Serial Number INF#J031093
OK - that's good. Also known as CSDK 2.20, IIRC.
>I read TechNote 5563, and in several passages you mention the C code
>cannot be compiled with a C++ compiler. So might this be the actual
>cause of my problem?
Yes; arbitrary C code (that is wholly acceptable to a C compiler) is
not, in general, C++ code. If you write in the appropriate subset of
C, you can compile C code with a C++ compiler, but it isn't trivial to
do it write. OTOH, it is not particularly difficult to do so, either.
There are two parts to the problem with ESQL/C code.
1. Those bits of the code that the ESQL/C compiler ignores (copies
through) need to be written in the C++ subset of C so that the C++
compiler will accept them. That means things like all functions
must be declared or defined before they are used, and all functions
must use function prototypes.
2. Those bits of the code that the ESQL/C compiler generates must be
made acceptable to the C++ compiler. That means that the C++
compiler must be told that the C functions that are called have a C
interface, not a C++ interface. This ensures that the compiler does
not mangle the function names. Also, there must be a prototype for
every such function. And there are places where the generated code
has to be cleaned up in some versions of ESQL/C. Little things like
using '(char *)0' in lieu of '(void *)0' or '(struct dohickey *)0'
irritate C++ compilers and they refuse to produce object code when
presented with such infelicities.
The esql++ script can't do anything about part 1; it does its utmost to
finagle the system to deal with the problems in part 2.
>Apart from that, I am not a sys admin, so I do not really want to
>install new scripts to our system.
You have a $HOME/bin directory? If so, you put the esql++ stuff there.
You'll need to futz around with the location of the esql*.h files, but
there's no inherent reason to install esql++ in $INFORMIXDIR -- I don't
on my machine, for example.
$ which esql++
/work/jleffler/bin/esql++
$
>BTW, the only reason I changed to CC compiler is that this seems to be
>the only compiler allowing me to include debugging information into the
>code. gcc does not allow that.
There could be a couple of related issues here. One, the cc compiler
that (probably) comes with the C++ compiler should also allow debugging.
Two, the problem may be that the esql script thinks that the -G and -g
options on the command line are intended for it and not for the C (or
C++) compiler. You can work around this by including the debug option
(-g) in with INFORMIXC:
INFORMIXC="CC -g -N -v"
In short, I think you need esql++, though it isn't as clear cut with
9.20 as earlier versions. The generated code is mostly pretty close
to clean (though trying to write const-correct code can still drive
you insane if you aren't very careful about what the Informix code is
allowed to do with "#define const /*nothing*/").
>Jonathan Leffler wrote:
>> Peter Christmeier wrote:
>> > I am just about modifying an existing C program that contains several
>> > ESQL commands to (obviously) access a database. I am working with
>> > HPUX 10.20 on a B180. The program used to be compiled using gcc, and
>> > I only changed to use HP's CC compiler.
>> >
>> > After removing all inaccuracies that gcc wouldn't have complained
>> > about like type castings, etc., there are two error messages that
>> > still reside. The following is a screenshot from the compilation:
>>
>> The biggest problem with this screen shot is the complete absence of the
>> esql script being used to do the compilation. That is a complete NoNo!
>> You must use the esql script to get the compilation and linking done.
>>
>> > /opt/langtools/lbin/cpp.ansi -I/opt/informix/incl/esql \\
>> > -D__hp9000s700 -D_PA_RISC1_1 -$ -Z -Dc_plusplus -D__cplusplus \\
>> > -D__hp9000s800 -D__hppa -D__hpux -D__unix -Dhp9000s800 -Dhppa \\
>> > -Dhpux -Dunix -I/opt/CC/include/CC -I/usr/include ppDump.c \\
>> > /var/tmp/AAAa15325.i
>> > /opt/CC/lbin/cfront +a0 +b1 +T/var/tmp/BAAa15325 +s \\
>> > +t/var/tmp/CAAa15325 +fppDump.c -g/var/tmp/DAAa15325.x +XCppDump.o \\
>> > </var/tmp/AAAa15325.i
>> > CC: "ppDump.ec", line 297: error: unexpected 1 argument for _iqnprep() (1265)
>> > CC: "ppDump.ec", line 310: error: undefined function _iqcddcl called (1286)
>> > CC: "ppDump.ec", line 310: error: undefined function _iqlocate_cursor called (1286)
>> > CC: "ppDump.ec", line 316: error: undefined function _iqdescribe called (1286)
>> > CC: "ppDump.ec", line 324: error: undefined function _iqdcopen called (1286)
>> > CC: "ppDump.ec", line 346: error: undefined function _iqcftch called (1286)
>> > CC: "ppDump.ec", line 363: error: undefined function _iqfree called (1286)
>> > CC: "ppDump.ec", line 599: error: unexpected 1 argument for _iqnprep() (1265)
>> > CC: "ppDump.ec", line 880: error: unexpected 1 argument for _iqnprep() (1265)
>> > CC: "ppDump.ec", line 1019: error: unexpected 1 argument for _iqnprep() (1265)
>> > CC: "ppDump.ec", line 1286: error: unexpected 1 argument for _iqnprep() (1265)
>> > CC: "ppDump.ec", line 1531: error: undefined function _iqconnect called (1286)
>> > CC: "ppDump.ec", line 1600: error: undefined function _iqdisconnect called (1286)
>> > removing ppDump.o
>> > removing /var/tmp/AAAa15325.i
>> > removing /var/tmp/BAAa15325
>> > removing /var/tmp/CAAa15325
>> > removing /var/