Reputation: 21
I am now attempting to make a simple "create table" C - embedded sql application with gcc.
My sqc file code:
#include <stdio.h>
#include <string.h>
#include <sqlca.h>
/* CREATE A DATABASE TABLE FOR TESTING COBOL-C-DB2 */
/* SQL includes */
EXEC SQL INCLUDE SQLCA;
EXEC SQL BEGIN DECLARE SECTION;
EXEC SQL END DECLARE SECTION;
int main()
{
EXEC SQL CREATE TABLE SYT006_COUNTRY(
KEYFIELD INT NOT NULL,
SL_ISO2 CHAR(2) NOT NULL,
BZ_COUNTRY CHAR(30) NOT NULL,
KZ_RISK CHAR(1) NOT NULL,
PRIMARY KEY (KEYFIELD)
);
return (0);
}
db2 prep does create a C file, setting a path in gcc to DB2s include folder does make for the line #include "sqladef.h" to work for example.
In re-written main function however it calls three functions which I cant find in headers:
#line 25 "create_table.sqc"
sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
#line 25 "create_table.sqc"
sqlacall((unsigned short)24,1,0,0,0L);
#line 25 "create_table.sqc"
sqlastop(0L);
And reports an error:
undefined reference to `sqlastrt'
And after writing -Wl in the gcc line for linking something to something I now get an error message:
/usr/bin/ld: cannot find : No such file or directory
collect2: error: ld returned 1 exit status
my script
db2start
db2 connect to sample
db2 prep create_table.sqc bindfile
db2 bind create_table.bnd
gcc -Wl, -Wimplicit -fno-stack-protector -trigraphs create_table.c -o runner -
I/home/nikica/sqllib/include
./runner
The "runner" executable is not created
Upvotes: 0
Views: 418
Reputation: 12267
These functions are part of the Db2 libraries. The header files supplied with Db2 have the function definitions etc. You have to use these.
Your example question:
omits the correct Db2 header files in your .sqc source
omits the library path and Db2 library from the linker command line
Study all the IBM examples are already in your Db2 installation (for example: in directory /home/db2inst1/sqllib/samples/c
). Copy this directory contents to your own home directory and Get those examples built and operating on your local database using the IBM build scripts that are in the same directory ( bldapp
, bldrtn
etc). This will be time well spent.
In your case, as you are building an application from embedded SQL in C, then you can use the sample script bldapp
to build your executables, and you should include additional header files in your .sqc file ( for example sqlenv.h
, sqlutil.h
, db2ApiDf.h
etc). The bldapp
script shows how to give the library path to the linker and how to include the required library that includes the functions referenced by the preprocessor output.
Upvotes: 1