How can I compile & and run an ESQL/C program on Linux Platform?

1.8k views Asked by At

I have checked the IBM official site for ESQL/C programming guide. I didn't find exact commands to compile and run. Do I need to install any packages to run? Can anyone tell me the commands to run these in Ubuntu?

1

There are 1 answers

5
Jonathan Leffler On BEST ANSWER

ESQL/C (Embedded SQL in C) uses C code for the bulk of the code, but uses special markers (either $ in Informix ESQL/C or EXEC SQL in both standard and Informix ESQL/C) to indicate where SQL statements need preprocessing to be converted into an appropriate series of C library function calls and C variable definitions, etc. The esql script is the compiler that automatically converts Informix ESQL/C source into first C and then object code and an executable (under options that are mainly the same as the C compiler's options, most of which are passed to the C compiler unchanged).

You need to have the Informix ClientSDK (CSDK) installed to be able to compile ESQL/C programs. That is installed by default when the server is installed, so the chances are you're OK if you're on a machine with a working Informix server on it (if it also has a working C compiler and development environment). It is also available as a separate standalone product which you could install if you don't have, and don't want, an Informix server on your machine. There are advantages for testing if the server is local (quicker access, and less danger of damaging production systems, amongst others).

Assuming you have got CSDK installed, you need to set the environment variable INFORMIXDIR to point where the software is installed (unless you chose to install it in /usr/informix or create a symlink /usr/informix that points to to where CSDK is installed). You'll also want to add $INFORMIXDIR/bin to your PATH. You're now ready to compile:

  • Compile .ec (ESQL/C source) files to object with the esql command:

    esql -c esqlc_source.ec
    

    Add other C compiler options as needed. Note that -g is intercepted by the esql script and you have to work hard to get it passed to the C compiler.

  • Consider compiling .c (C source) files that use an ESQL/C header with the esql script too. This will pass the correct directory for the headers to the C compiler automatically. More likely, you'll use:

    ${CC} -c c_source.c -I${INFORMIXDIR}/incl/esql
    
  • For linking, use the esql script to do it. It will provide the correct libraries (and object files) to the compiler, which it will invoke as the linker:

    esql -o program c_source.o esqlc_source.o
    

    You can add other libraries and library directories as usual.

You have the program compiled; now you need to run it. The chances are that you won't find the libraries automatically. You will need to think about adding some directories to either LD_LIBRARY_PATH or modify /etc/ld.so.conf to pick up the extra directories, or create symlinks to the Informix libraries from a place that will be picked up automatically (e.g. /usr/lib or /usr/lib64, or perhaps /usr/local/lib) to where the libraries are installed.

You need to add at minimum:

  • $INFORMIXDIR/lib
  • $INFORMIXDIR/lib/esql

Under some circumstances, you may need to add other library directories found under $INFORMIXDIR/lib as well, but usually not.

You should then be able to run the program. Using ldd program will let you know when you've got the settings right.