[unixODBC-support] Building ODBC sample on Ubuntu

Martin J. Evans bohica at ntlworld.com
Sat Mar 12 18:44:53 GMT 2016

You only need the unixodbc package and the unixodbc-dev package. To compile you need -Idir where dir is where sql*.h are located. To link you need -Ldir where dir is where libodbc.so libodbcinst.so are located and a -lodbc and -lodbcinst. So cc -I/dir -Ldir xxx.c -Ldir -lodbc -lodbcinst should do it.

Martin J. Evans 

On 12 Mar 2016, 18:34, at 18:34, David Adler <dadler at adtechgeospatial.com> wrote:
>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;
>   SQLRETURN ret;
>   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
>/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.
>unixODBC-support mailing list
>unixODBC-support at mailman.unixodbc.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.unixodbc.org/pipermail/unixodbc-support/attachments/20160312/ca3e606b/attachment.html>

More information about the unixODBC-support mailing list