This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: compile and link a C with embedded SQl program using gcc and DB2
- From: "Bras, Gerard" <gbras at anacomp dot com>
- To: "Sinha, Vinita" <Vinita_Sinha at tesseract dot com>, <gcc-help at gcc dot gnu dot org>
- Date: Thu, 19 Aug 2004 14:44:24 -0400
- Subject: RE: compile and link a C with embedded SQl program using gcc and DB2
Vinita,
You are lacking the "-l" lib directives on your link line. You have the "-L" directives which tell the link WHERE to look. But you also need to specify WHICH actual libraries to link in. I don't know a thing about DB2 on NT but my guess is it'll be pretty obvious when you look in If it isn't there is always the DB2 web site which I'm has what you're looking for.
Acutally, now that I look closer you seem to have tried to combine bothe functions into a single "-L" directive. Try changing:
-L"C:\Program Files\SQLLIB\lib\db2api.lib
into
-L"C:\Program Files\SQLLIB\lib" -ldb2api.lib
Best of luck.
Gerard Bras
-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org]On
Behalf Of Sinha, Vinita
Sent: Thursday, August 19, 2004 2:30 PM
To: gcc-help@gcc.gnu.org
Subject: compile and link a C with embedded SQl program using gcc and
DB2
Hi,
I am trying to compile a simple sql program using c and DB2 . It fails in the link step.Which are the other Libraries I need to add in the link step to make it work ?
This is the bat file for compile
@echo off
rem Licensed Materials - Property of IBM
if exist "%1.sqx" goto embedded
if exist "%1.sqc" goto embedded
goto non_embedded
:embedded
rem Precompile and bind the program.
call embprep %1 %2 %3 %4
rem Compile the program.
if exist "%1.cxx" goto cpp_emb
goto link_embedded
:cpp_emb
rem Link the program.
:link_embedded
gcc -I"C:\Program Files\SQLLIB\include" -I"C:\Program Files\SQLLIB\samples\c" -I"C:\Program Files\SQLLIB\samples\cli" -O0 -g3 -Wall -c -fmessage-length=0 -osqlexample.o sqlexample.c
gcc -L"C:\Program Files\SQLLIB\include" -L"C:\Program Files\SQLLIB\lib\db2api.lib" -L"C:\Program Files\SQLLIB\samples\c" -L"C:\Program Files\SQLLIB\bin" -o2006b.exe sqlexample.o
goto exit
The compile log with errors :
C:\R20006\cPrograms>bldappgcc.bat sqlexample Replica1 db2admin db2admin
Database Connection Information
Database server = DB2/NT 8.1.0
SQL authorization ID = DB2ADMIN
Local database alias = REPLICA1
LINE MESSAGES FOR sqlexample.sqc
------ --------------------------------------------------------------------
SQL0060W The "C" precompiler is in progress.
SQL0091W Precompilation or binding was ended with "0"
errors and "0" warnings.
LINE MESSAGES FOR sqlexample.bnd
------ --------------------------------------------------------------------
SQL0061W The binder is in progress.
SQL0091N Binding was ended with "0" errors and "0" warnings.
DB20000I The SQL command completed successfully.
C:\R20006\cPrograms>rem Compile the program.
C:\R20006\cPrograms>if exist "sqlexample.cxx" goto cpp_emb
C:\R20006\cPrograms>goto link_embedded
C:\R20006\cPrograms>gcc -I"C:\Program Files\SQLLIB\include" -I"C:\Program Files\
SQLLIB\samples\c" -I"C:\Program Files\SQLLIB\samples\cli" -O0 -g3 -Wall -c -fmes
sage-length=0 -osqlexample.o sqlexample.c
sqlexample.sqc:73:18: warning: character constant too long for its type
sqlexample.sqc:73:30: warning: character constant too long for its type
sqlexample.sqc:73:42: warning: character constant too long for its type
sqlexample.sqc: In function `main':
sqlexample.sqc:73: warning: passing arg 1 of `DbConnect' makes pointer from inte
ger without a cast
sqlexample.sqc:73: warning: passing arg 2 of `DbConnect' makes pointer from inte
ger without a cast
sqlexample.sqc:73: warning: passing arg 3 of `DbConnect' makes pointer from inte
ger without a cast
sqlexample.sqc:87: warning: control reaches end of non-void function
sqlexample.sqc: In function `TbBasicSelect':
sqlexample.sqc:121: warning: unused variable `rc'
C:\R20006\cPrograms>gcc -L"C:\Program Files\SQLLIB\include" -L"C:\Program Files\
SQLLIB\lib\db2api.lib" -L"C:\Program Files\SQLLIB\samples\c" -L"C:\Program File
s\SQLLIB\bin" -o2006b.exe sqlexample.o
sqlexample.o(.text+0xce): In function `main':
/cygdrive/c/R20006/cPrograms/sqlexample.sqc:84: undefined reference to `_sqlastr
t@12'
sqlexample.o(.text+0xfd):/cygdrive/c/R20006/cPrograms/sqlexample.sqc:84: undefin
ed reference to `_sqlacall@20'
sqlexample.o(.text+0x10c):/cygdrive/c/R20006/cPrograms/sqlexample.sqc:84: undefi
ned reference to `_sqlastop@4'
sqlexample.o(.text+0x24a): In function `DbConnect':
/cygdrive/c/R20006/cPrograms/sqlexample.sqc:105: undefined reference to `_sqlast
rt@12'
sqlexample.o(.text+0x271):/cygdrive/c/R20006/cPrograms/sqlexample.sqc:105: undef
ined reference to `_sqlaaloc@16'
sqlexample.o(.text+0x31c):/cygdrive/c/R20006/cPrograms/sqlexample.sqc:105: undef
ined reference to `_sqlasetda@24'
sqlexample.o(.text+0x34b):/cygdrive/c/R20006/cPrograms/sqlexample.sqc:105: undef
ined reference to `_sqlacall@20'
sqlexample.o(.text+0x35a):/cygdrive/c/R20006/cPrograms/sqlexample.sqc:105: undef
ined reference to `_sqlastop@4'
sqlexample.o(.text+0x380):/cygdrive/c/R20006/cPrograms/sqlexample.sqc:111: undef
ined reference to `_sqlastrt@12'
sqlexample.o(.text+0x3a7):/cygdrive/c/R20006/cPrograms/sqlexample.sqc:111: undef
ined reference to `_sqlaaloc@16'
sqlexample.o(.text+0x406):/cygdrive/c/R20006/cPrograms/sqlexample.sqc:111: undef
ined reference to `_sqlasetda@24'
sqlexample.o(.text+0x435):/cygdrive/c/R20006/cPrograms/sqlexample.sqc:111: undef
ined reference to `_sqlacall@20'
sqlexample.o(.text+0x444):/cygdrive/c/R20006/cPrograms/sqlexample.sqc:111: undef
ined reference to `_sqlastop@4'
sqlexample.o(.text+0x4b1): In function `TbBasicSelect':
/cygdrive/c/R20006/cPrograms/sqlexample.sqc:126: undefined reference to `_sqlast
rt@12'
sqlexample.o(.text+0x4d8):/cygdrive/c/R20006/cPrograms/sqlexample.sqc:126: undef
ined reference to `_sqlaaloc@16'
sqlexample.o(.text+0x538):/cygdrive/c/R20006/cPrograms/sqlexample.sqc:126: undef
ined reference to `_sqlasetda@24'
sqlexample.o(.text+0x567):/cygdrive/c/R20006/cPrograms/sqlexample.sqc:126: undef
ined reference to `_sqlacall@20'
sqlexample.o(.text+0x576):/cygdrive/c/R20006/cPrograms/sqlexample.sqc:126: undef
ined reference to `_sqlastop@4'
collect2: ld returned 1 exit status
C:\R20006\cPrograms>rem link -debug -out:sqlexample.exe sqlexample.obj utilemb.o
bj db2api.lib
C:\R20006\cPrograms>goto exit
The system cannot find the batch label specified - exit
C:\R20006\cPrograms>
Any help will be appreciated
Thanks
Vinita