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\include" -L"D:\SQLLIB\lib"
The execution was terminated. It threw the messages as below,
C:\DOCUME~1\db2admin\LOCALS~1\Temp/ccCMaaaa.o(.text+0x42):sample.c:
undefined reference to `sqlastrt@12'
C:\DOCUME~1\db2admin\LOCALS~1\Temp/ccCMaaaa.o(.text+0x69):sample.c:
undefined reference to `sqlaaloc@16'
C:\DOCUME~1\db2admin\LOCALS~1\Temp/ccCMaaaa.o(.text+0xba):sample.c:
undefined reference to `sqlasetda@24'
C:\DOCUME~1\db2admin\LOCALS~1\Temp/ccCMaaaa.o(.text+0xe9):sample.c:
undefined reference to `sqlacall@20'
C:\DOCUME~1\db2admin\LOCALS~1\Temp/ccCMaaaa.o(.text+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
Is there something I lose to link during compiling?
Please~
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.
> 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\include" -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:
http://publib.boulder.ibm.com/infocenter/db2luw/v9r5/topic/com.ibm.db2.l
uw.apdv.embed.doc/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.
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.