I am trying to compile a simple ODBC and C example on Windows XP SP2.
I have Cygwin_NT 5.1.
This is the code (obtained from
http://www.easysoft.com/developer/la...dm_fns_drivers)
i am attempting to compile.
ODBCTest.c
#include <stdio.h>
#include <windows.h>
#include <sql.h>
#include <sqlext.h>
main() {
SQLHENV env;
char dsn[256];
char desc[256];
SQLSMALLINT dsn_ret;
SQLSMALLINT desc_ret;
SQLUSMALLINT direction;
SQLRETURN ret;
SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE , &env);
SQLSetEnvAttr(e nv, SQL_ATTR_ODBC_V ERSION, (void *) SQL_OV_ODBC3, 0);
direction = SQL_FETCH_FIRST ;
while(SQL_SUCCE EDED(ret = SQLDataSources( env, direction,
dsn, sizeof(dsn), &dsn_ret,
desc, sizeof(desc), &desc_ret))) {
direction = SQL_FETCH_NEXT;
printf("%s - %s\n", dsn, desc);
if (ret == SQL_SUCCESS_WIT H_INFO) printf("\tdata truncation\n");
}
}
Makefile
CC=gcc
INCPATH=-I/usr/include -Iinclude
LIBS=-L. -lodbc32
LD=ld
all: clean ODBCTest.exe
ODBCTest.o : ODBCTest.c
$(CC) $(INCPATH) $(CFLAGS) -o ODBCTest.o -c ODBCTest.c
ODBCTest.exe : ODBCTest.o
$(CC) $(LIBS) $(CFLAGS) -o ODBCTest.exe ODBCTest.o
clean:
-rm *.o
-rm *.exe
Make output and Errors:
$ make
rm *.o
rm *.exe
rm: cannot remove `*.exe': No such file or directory
make: [clean] Error 1 (ignored)
gcc -I/usr/include -Iinclude -o ODBCTest.o -c ODBCTest.c
gcc -L. -lodbc32 -o ODBCTest.exe ODBCTest.o
ODBCTest.o:ODBC Test.c:(.text+0 x4a): undefined reference to
`_SQLAllocHandl e@12'
ODBCTest.o:ODBC Test.c:(.text+0 x70): undefined reference to
`_SQLSetEnvAttr @16'
ODBCTest.o:ODBC Test.c:(.text+0 xca): undefined reference to
`_SQLDataSource s@32'
collect2: ld returned 1 exit status
make: *** [ODBCTest.exe] Error 1
Things i have checked:
libodbc32.a exists in c:\cygwin\lib\w 32api.
If i remove the above lib, i get a "lib not found" kind of error when
i run make, meaning this is the lib make is using and there is no path
issue.
if i edit libodbc32.a in a binary editor, i can see the all the three
functions mentioned in the error (_SQLAllocHandl e@12,
_SQLSetEnvAttr@ 16 and _SQLDataSources @32) exist.
How can i fix these linking errors?
Thanks
PG
I have Cygwin_NT 5.1.
This is the code (obtained from
http://www.easysoft.com/developer/la...dm_fns_drivers)
i am attempting to compile.
ODBCTest.c
>>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>
#include <windows.h>
#include <sql.h>
#include <sqlext.h>
main() {
SQLHENV env;
char dsn[256];
char desc[256];
SQLSMALLINT dsn_ret;
SQLSMALLINT desc_ret;
SQLUSMALLINT direction;
SQLRETURN ret;
SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE , &env);
SQLSetEnvAttr(e nv, SQL_ATTR_ODBC_V ERSION, (void *) SQL_OV_ODBC3, 0);
direction = SQL_FETCH_FIRST ;
while(SQL_SUCCE EDED(ret = SQLDataSources( env, direction,
dsn, sizeof(dsn), &dsn_ret,
desc, sizeof(desc), &desc_ret))) {
direction = SQL_FETCH_NEXT;
printf("%s - %s\n", dsn, desc);
if (ret == SQL_SUCCESS_WIT H_INFO) printf("\tdata truncation\n");
}
}
>>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>
>>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>
INCPATH=-I/usr/include -Iinclude
LIBS=-L. -lodbc32
LD=ld
all: clean ODBCTest.exe
ODBCTest.o : ODBCTest.c
$(CC) $(INCPATH) $(CFLAGS) -o ODBCTest.o -c ODBCTest.c
ODBCTest.exe : ODBCTest.o
$(CC) $(LIBS) $(CFLAGS) -o ODBCTest.exe ODBCTest.o
clean:
-rm *.o
-rm *.exe
>>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>
>>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>
rm *.o
rm *.exe
rm: cannot remove `*.exe': No such file or directory
make: [clean] Error 1 (ignored)
gcc -I/usr/include -Iinclude -o ODBCTest.o -c ODBCTest.c
gcc -L. -lodbc32 -o ODBCTest.exe ODBCTest.o
ODBCTest.o:ODBC Test.c:(.text+0 x4a): undefined reference to
`_SQLAllocHandl e@12'
ODBCTest.o:ODBC Test.c:(.text+0 x70): undefined reference to
`_SQLSetEnvAttr @16'
ODBCTest.o:ODBC Test.c:(.text+0 xca): undefined reference to
`_SQLDataSource s@32'
collect2: ld returned 1 exit status
make: *** [ODBCTest.exe] Error 1
>>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>
libodbc32.a exists in c:\cygwin\lib\w 32api.
If i remove the above lib, i get a "lib not found" kind of error when
i run make, meaning this is the lib make is using and there is no path
issue.
if i edit libodbc32.a in a binary editor, i can see the all the three
functions mentioned in the error (_SQLAllocHandl e@12,
_SQLSetEnvAttr@ 16 and _SQLDataSources @32) exist.
How can i fix these linking errors?
Thanks
PG
Comment