Building ODBC sample on Ubuntu

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Building ODBC sample on Ubuntu

David Adler
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;

   SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
   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@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.
https://www.avast.com/antivirus

_______________________________________________
unixODBC-support mailing list
[hidden email]
http://mailman.unixodbc.org/mailman/listinfo/unixodbc-support
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Building ODBC sample on Ubuntu

Martin J. Evans

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, at 18:34, David Adler <[hidden email]> 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;

SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
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@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.
https://www.avast.com/antivirus



unixODBC-support mailing list
[hidden email]
http://mailman.unixodbc.org/mailman/listinfo/unixodbc-support

_______________________________________________
unixODBC-support mailing list
[hidden email]
http://mailman.unixodbc.org/mailman/listinfo/unixodbc-support
ML
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Building ODBC sample on Ubuntu

ML
David,

Regarding packages, I searched Ubuntu's package search and found this page: http://packages.ubuntu.com/trusty/unixodbc-bin
At the bottom there are two links to browse files in the package. One of them is "ODBCManageDataSourcesQ4".
So, the package you want to install is "unixodbc-bin".

The hard way I learnt that "ODBCConfig" was replaced by "ODBCCreateDataSourceQ4" (wizard-like) and "ODBCManageDataSourcesQ4".
Remember to prefix any of those with "sudo" if you will create/edit any ODBC system setting.

Regards,
zxMarce.

On 2016-03-12 15:44, Martin J. Evans wrote:

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, at 18:34, David Adler <[hidden email]> 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;

   SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
   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@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

_______________________________________________
unixODBC-support mailing list
[hidden email]
http://mailman.unixodbc.org/mailman/listinfo/unixodbc-support
Loading...