how to develop embedded SQL program by C language?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Laurence

    #1

    how to develop embedded SQL program by C language?

    Hi there,

    The following is my first embedded SQL program on Windows, which is
    coded by C language.

    /* sample.sqc */
    #include <stdio.h>
    EXEC SQL INCLUDE SQLCA;
    EXEC SQL BEGIN DECLARE SECTION;
    EXEC SQL INCLUDE 'staff.h'; /* generated by db2dclgn */
    EXEC SQL END DECLARE SECTION;
    int main(int argc, char *argv[])
    {
    EXEC SQL
    select dept into :staff.dept
    from staff
    where id = 10;
    printf("The ID no. of Sanders is: %d\n", staff.dept);
    return 0;
    }

    I did db2 prep and bind commands successfully. But when I did the
    compiling as below,

    D:\Dev-Cpp\bin>gcc.exe "D:\Dev-Cpp\c\sample.c" -o "D:\Dev-Cpp\c
    \sample.exe" -I"D:\SQLLIB\inc lude" -L"D:\SQLLIB\lib "

    The execution was terminated. It threw the messages as below,

    C:\DOCUME~1\db2 admin\LOCALS~1\ Temp/ccCMaaaa.o(.tex t+0x42):sample. c:
    undefined reference to `sqlastrt@12'
    C:\DOCUME~1\db2 admin\LOCALS~1\ Temp/ccCMaaaa.o(.tex t+0x69):sample. c:
    undefined reference to `sqlaaloc@16'
    C:\DOCUME~1\db2 admin\LOCALS~1\ Temp/ccCMaaaa.o(.tex t+0xba):sample. c:
    undefined reference to `sqlasetda@24'
    C:\DOCUME~1\db2 admin\LOCALS~1\ Temp/ccCMaaaa.o(.tex t+0xe9):sample. c:
    undefined reference to `sqlacall@20'
    C:\DOCUME~1\db2 admin\LOCALS~1\ Temp/ccCMaaaa.o(.tex t+0xf8):sample. c:
    undefined reference to `sqlastop@4'
    collect2: ld returned 1 exit status

    I don't konw hot to fix it....

    Could somebody help me? I'll appreciate that.

    Laurence
  • Laurence

    #2
    Re: how to develop embedded SQL program by C language?

    By the way, I'm using DB2 V7.2 Enterprise Edition.

    Is there something I lose to link during compiling?


    Please~

    Comment

    • gimme_this_gimme_that@yahoo.com

      #3
      Re: how to develop embedded SQL program by C language?

      To compile that C program you have to run the file through a
      precompiler.

      It's unlikely you'll be able to use gcc - unless the DB2 libraries you
      access are compatible with DB2.

      Look for a C compiler and for C header files in your DB2 EE.


      Comment

      • Dave Hughes

        #4
        Re: how to develop embedded SQL program by C language?

        Laurence wrote:
        Hi there,
        >
        The following is my first embedded SQL program on Windows, which is
        coded by C language.
        >
        [snip]
        >
        I did db2 prep and bind commands successfully. But when I did the
        compiling as below,
        >
        D:\Dev-Cpp\bin>gcc.exe "D:\Dev-Cpp\c\sample.c" -o "D:\Dev-Cpp\c
        \sample.exe" -I"D:\SQLLIB\inc lude" -L"D:\SQLLIB\lib "
        [snip]

        gcc isn't a supported compiler for building C with embedded SQL in the
        Windows environment; I can't remember what the supported environments
        were for v7.2, but for 9.5 you can find the list at:


        uw.apdv.embed.d oc/doc/r0020877.html

        IIRC, the MSVC environment has always been supported - not sure about
        the Intel compiler. You might want to try this with MSVC 2005 express
        (which is free). BTW, gcc is supported for use with DB2 on Linux.

        As to what's actually wrong here - different object formats perhaps? I
        recall running into something similar when I tried to get Borland's C++
        compiler working with DB2 many years ago.


        Cheers,

        Dave.

        Comment

        • Laurence

          #5
          Re: how to develop embedded SQL program by C language?

          Hi,

          I did it after tried over and over again. Both Visual C++ 2005 Express
          and Dev C++ (gcc) are supported.

          With Visual C++ 2005 Express:
          Compile Syntax =cl -Zi -Od -c -W2 -DWIN32 sample.c
          Link Syntax =link -debug -out:sample.exe sample.obj db2api.lib

          With Dev C++ (gcc):
          Compile & Link Syntax =gcc.exe "sample.c" -o "sample.exe " -I"%DB2PATH
          %\include" -L"%DB2PATH%\lib " -l"db2api"


          For your information, and thanks for all your replies.

          Comment

          Working...