[unixODBC-support] Building ODBC sample on Ubuntu

David Adler dadler at adtechgeospatial.com
Sat Mar 12 18:31:50 GMT 2016

I just want to run a test program using ODBC calls on Ubuntu but can't 
find any information on what includes to use or how to link. Is there a 
sample makefile? I've used ODBC on Windows with no problem.

Also unixodbc documentation refers to ODBCConfig but this doesn't seem 
to be on my system.

There are also references to the package unixodbc-gui-qt but apt-get 
can't find it.

This is the program I'm trying to run:
#include <stdio.h>
#include <sql.h>
#include <sqlext.h>

main() {
   SQLHENV env;
   char driver[256];
   char attr[256];
   SQLSMALLINT driver_ret;
   SQLSMALLINT attr_ret;
   SQLUSMALLINT direction;

   SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);

   direction = SQL_FETCH_FIRST;
   while(SQL_SUCCEEDED(ret = SQLDrivers(env, direction,
                        driver, sizeof(driver), &driver_ret,
                        attr, sizeof(attr), &attr_ret))) {
     direction = SQL_FETCH_NEXT;
     printf("%s - %s\n", driver, attr);
     if (ret == SQL_SUCCESS_WITH_INFO) printf("\tdata truncation\n");

It compiles but fails with
user at ubuntuvm:~/odbc$ make
Linking CXX executable odbctest
CMakeFiles/odbctest.dir/odbctest.cpp.o: In function `main':
/home/user/odbc/odbctest.cpp:14: undefined reference to `SQLAllocHandle'
/home/user/odbc/odbctest.cpp:15: undefined reference to `SQLSetEnvAttr'
/home/user/odbc/odbctest.cpp:18: undefined reference to `SQLDrivers'
collect2: error: ld returned 1 exit status
make[2]: *** [odbctest] Error 1
make[1]: *** [CMakeFiles/odbctest.dir/all] Error 2
make: *** [all] Error 2

This email has been checked for viruses by Avast antivirus software.

More information about the unixODBC-support mailing list