【发布时间】:2012-12-23 07:04:11
【问题描述】:
我正在尝试将我的 c++ 客户端连接到 PostgreSQL 数据库。我不断收到 otlv4.h|12406|undefined reference to `SQLFreeHandle@8' 和许多其他未定义的引用错误。
要获取头文件,请转到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;
}
【问题讨论】:
-
您是否安装了 [PgODBC][1]? [1]:postgresql.org/ftp/odbc/versions/msi
-
是的,我已经安装好了
-
SQLFreeHandle 和任何其他启动 SQL 的函数都是 ODBC API 函数。它们由您应该链接到的 ODBC 驱动程序管理器提供。无论您是否有 ODBC 驱动程序,您都应该链接到 ODBC 驱动程序管理器。
标签: c++ sql postgresql odbc otl