ODBC link-time error

M

mrambil

Hi,
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;
#else
#define DEBUG(str)
#endif

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

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

SQLDisconnect(hdbc);
SQLFreeConnect(hdbc);
SQLFreeEnv(henv);
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/lib/gcc/mingw32/3.4.2/include"
-I"C:/Dev-Cpp5/include/c++/3.4.2/backward"
-I"C:/Dev-Cpp5/include/c++/3.4.2/mingw32"
-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
`SQLAllocHandle@12'
main.o(.text+0x160):main.cpp: undefined reference to
`SQLAllocConnect@8'
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 :
libodbccp32.a
libodbc32.a

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

Any help welcome,
Regards,

Mohamed Rambil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top