2

I am trying to connect my c++ client to an PostgreSQL DB. I keep getting otlv4.h|12406|undefined reference to `SQLFreeHandle@8' and many other undefined reference errors.

To get the header file go to http://otl.sourceforge.net/otl3_down.htm

#include <iostream>

using namespace std;

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// #define OTL_ODBC_UNIX // uncomment this line if UnixODBC is used
#define OTL_ODBC_ALTERNATE_RPC
#if !defined(_WIN32) && !defined(_WIN64)
#define OTL_ODBC
#else
#define OTL_ODBC_POSTGRESQL // required with PG ODBC on Windows
#endif
#include "otlv4.h" // include the OTL 4.0 header file

otl_connect db; // connect object

int main()
{

    otl_connect::otl_initialize(); // initialize ODBC environment

    db.rlogon("postgres/changeme@numbers");

    db.commit();

    cout << "Hello world!" << endl;

    db.logoff(); // disconnect from ODBC
    return 0;
}
Bhavik Ambani
  • 6,557
  • 14
  • 55
  • 86
Roland Sams
  • 173
  • 1
  • 2
  • 12
  • Did you install [PgODBC][1]? [1]: http://www.postgresql.org/ftp/odbc/versions/msi/ – mvp Dec 23 '12 at 07:22
  • Yep, I have it installed – Roland Sams Dec 23 '12 at 07:38
  • SQLFreeHandle and any other function starting SQL are ODBC API functions. They are provided by the ODBC driver manager which you should be linking to. Irrespective of whether you have an ODBC Driver or not you should be linking to the ODBC driver manager. – bohica Jan 08 '13 at 08:59

1 Answers1

0

When I did connection from Windows to PostgreSQL using ODBC, I used DSN-less approach. It requires zero input from user perspective - user does not need to know what ODBC is and how to configure ODBC source (DSN).

Typical way to use DSN-less connection is to use string like below as your ODBC connection string:

Driver=PostgreSQL;Server=hostname;Database=mypgdb;UID=username;PWD=password

Note that driver name may need to be adjusted depending on version and ANSI vs Unicode flavors.

mvp
  • 111,019
  • 13
  • 122
  • 148