By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,089 Members | 1,340 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,089 IT Pros & Developers. It's quick & easy.

ODBC link-time error

P: n/a
I've got some problems using ODBC with C++.

First, I use Dev-cpp with gcc/g++ v3.4.2 on Win XP.
I got to connect to a system DSN installed on my computer so I use the
standard SQL API provided with my compiler.
Here is a code snippet from my sources :

#include <windows.h>
#include <iostream>
#include <sql.h>
#include <sqlext.h>
#include <sqltypes.h>
#include <odbcinst.h>
#include <sqlucode.h>
#define STR_LEN 30
#define _DEBUG 1
#if _DEBUG
#define DEBUG(str) cout<<str<<endl;
#define DEBUG(str)

SQLHENV henv; /* environment handle */
SQLHDBC hdbc; /* connection handle */
HSTMT hstmt; /* statement handle */
SDWORD retcode; /* return code */
UCHAR info[STR_LEN]; /* info string for SQLGetInfo
int main(void){
retcode = SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&hen v);
retcode = SQLAllocConnect(henv,&hdbc);
retcode = SQLConnect(hdbc, (SQLCHAR*)"SAGE_GESCOM", SQL_NTS,
retcode = SQLGetInfo(hdbc,SQL_DBMS_VER, &info, STR_LEN,&inf);

printf("Current DBMS version is %s\n", info);

return 0;

As you can see, this code is very simple. It's purpose is to connect to
a given DSN (SAGE_GESCOM), with a given userid (Mo) and a given
password (\0). IMO it should work fine, if only I could manage to
compile and link it !

Here are the command lines for compiling and linking and the errors I
get from the linker :

g++.exe -c main.cpp -o main.o
-I"C:/Dev-Cpp5/include/c++/3.4.2" -I"C:/Dev-Cpp5/include"

g++.exe main.o -o "sageedi.exe" -L"C:/Dev-Cpp5/lib"
main.o(.text+0x142):main.cpp: undefined reference to
main.o(.text+0x160):main.cpp: undefined reference to
main.o(.text+0x1a6):main.cpp: undefined reference to `SQLConnect@28'
main.o(.text+0x1dc):main.cpp: undefined reference to `SQLGetInfo@20'
main.o(.text+0x206):main.cpp: undefined reference to `SQLDisconnect@4'
main.o(.text+0x216):main.cpp: undefined reference to `SQLFreeConnect@4'
main.o(.text+0x226):main.cpp: undefined reference to `SQLFreeEnv@4'
collect2: ld returned 1 exit status

Cannot understand why the linker spits such errors. The libraries I
have in my C:/Dev-Cpp5/lib directory are :

I guess a library is missing in this dir, but I don't know which and
where to retrieve it.

Any help welcome,

Mohamed Rambil

Jul 23 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.