i am new to building apps using C. i have written the following piece of code..
//contents of test.sqc
#include <stdio.h>
#include <stdlib.h>
exec sql include sqlca;
exec sql begin declare section;
short bp;
exec sql end declare section;
int main()
{
EXEC SQL CONNECT TO sample;
printf("connected to sample\n");
exec sql
select bufferpoolid
INTO :bp
from syscat.bufferpools
where bpname='IBMDEFAULTBP';
printf("the bpname : %d\n",bp);
EXEC SQL CONNECT RESET;
}
i precompile it using db2 prep test.sqc bindfile. ( after connecting to sample database ofcourse)
that results in test.c and the bind file. the C file is as follows.
static char sqla_program_id[162] =
{
42,0,65,68,65,75,65,73,84,69,83,84,32,32,32,32,52,65,77,54,
83,99,71,87,48,49,49,49,49,32,50,32,8,0,80,78,71,49,54,32,
32,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0
};
#include "sqladef.h"
static struct sqla_runtime_info sqla_rtinfo =
{{'S','Q','L','A','R','T','I','N'}, sizeof(wchar_t), 0, {' ',' ',' ',' '}};
static const short sqlIsLiteral = SQL_IS_LITERAL;
static const short sqlIsInputHvar = SQL_IS_INPUT_HVAR;
#line 1 "test.sqc"
#include <stdio.h>
#include <stdlib.h>
/*
exec sql include sqlca;
*/
/* SQL Communication Area - SQLCA - structures and constants */
#include "sqlca.h"
struct sqlca sqlca;
#line 4 "test.sqc"
/*
exec sql begin declare section;
*/
#line 6 "test.sqc"
short bp;
/*
exec sql end declare section;
*/
#line 8 "test.sqc"
int main()
{
/*
EXEC SQL CONNECT TO sample;
*/
{
#line 13 "test.sqc"
sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
#line 13 "test.sqc"
sqlaaloc(2,1,1,0L);
{
struct sqla_setdata_list sql_setdlist[1];
#line 13 "test.sqc"
sql_setdlist[0].sqltype = 460; sql_setdlist[0].sqllen = 7;
#line 13 "test.sqc"
sql_setdlist[0].sqldata = (void*)"sample";
#line 13 "test.sqc"
sql_setdlist[0].sqlind = 0L;
#line 13 "test.sqc"
sqlasetdata(2,0,1,sql_setdlist,NULL,0L);
}
#line 13 "test.sqc"
sqlacall((unsigned short)29,4,2,0,0L);
#line 13 "test.sqc"
sqlastop(0L);
}
#line 13 "test.sqc"
printf("connected to sample\n");
/*
exec sql
select bufferpoolid
INTO :bp
from syscat.bufferpools
where bpname='IBMDEFAULTBP';
*/
{
#line 20 "test.sqc"
sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
#line 20 "test.sqc"
sqlaaloc(3,1,2,0L);
{
struct sqla_setdata_list sql_setdlist[1];
#line 20 "test.sqc"
sql_setdlist[0].sqltype = 500; sql_setdlist[0].sqllen = 2;
#line 20 "test.sqc"
sql_setdlist[0].sqldata = (void*)&bp;
#line 20 "test.sqc"
sql_setdlist[0].sqlind = 0L;
#line 20 "test.sqc"
sqlasetdata(3,0,1,sql_setdlist,NULL,0L);
}
#line 20 "test.sqc"
sqlacall((unsigned short)24,1,0,3,0L);
#line 20 "test.sqc"
sqlastop(0L);
}
#line 20 "test.sqc"
printf("the bpname : %d\n",bp);
/*
EXEC SQL CONNECT RESET;
*/
{
#line 24 "test.sqc"
sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
#line 24 "test.sqc"
sqlacall((unsigned short)29,3,0,0,0L);
#line 24 "test.sqc"
sqlastop(0L);
}
#line 24 "test.sqc"
}
now when i try to compile this i get link errors. my link directories are right. i just cant seem to get whats the problem. compiler errors are
ompiler: Default compiler
Executing gcc.exe...
gcc.exe "C:\Documents and Settings\png16\My Documents\Working on Recently\Cprog\test.c" -o "C:\Documents and Settings\png16\My Documents\Working on Recently\Cprog\test.exe" -I"C:\Program Files\IBM\SQLLIB\include" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" -L"C:\Program Files\IBM\SQLLIB\lib"
C:\DOCUME~1\png16\LOCALS~1\Temp/ccKMaaaa.o(.text+0x42):test.c: undefined reference to `[Email Address Removed] undefined reference to `[Email Address Removed] undefined reference to `[Email Address Removed] undefined reference to `[Email Address Removed] undefined reference to `[Email Address Removed] undefined reference to `[Email Address Removed] undefined reference to `[Email Address Removed] undefined reference to `[Email Address Removed] undefined reference to `[Email Address Removed] undefined reference to `[Email Address Removed] undefined reference to `[Email Address Removed] undefined reference to `[Email Address Removed] undefined reference to `[Email Address Removed] ld returned 1 exit status
Execution terminated
could anyone please guide me on this one. if i want to build a C application, how do i go about it. i've followed everything on IBM infocenter. cant seem to get it.
thanks and regards,
anand
DB2 & UDB email list listserv db2-l LazyDBA home page