469,908 Members | 2,212 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,908 developers. It's quick & easy.

sqlext.h - ODBC link time error - dev-c++ IDE with mingw compiler

trying the following code to test SQL connection to MS SQL server using
machine DNS name.

receiving errors:
[linker error] undefined reference to 'SQLAllocEnv@4'
[linker error] undefined reference to 'SQLAllocConnect@8'
(etc. for all SQL function calls in the code)

using Dev-C++ 4.9.9.2 and the latest mingw WindowsAPI package (where
the sql header files are)

I've found others who have had the same problem, but no solution -
going nuts!

test code:

#include <windows.h>
#include <sqlext.h>
#include <cstdlib>
#include <iostream>

int main(int argc, char *argv[])
{
HENV hEnv = NULL; // Env Handle from SQLAllocEnv()
HDBC hDBC = NULL; // Connection handle
HSTMT hStmt = NULL;// Statement handle
UCHAR szDSN[SQL_MAX_DSN_LENGTH] = "mydsn";// Data Source Name
buffer
UCHAR szUID[13] = "username";// User ID buffer
UCHAR szPasswd[7] = "passwd";// Password buffer
UCHAR szModel[128];// Model buffer
SDWORD cbModel;// Model buffer bytes recieved
UCHAR szSqlStr[128]= "SELECT test FROM testtable where test =
'test_success'";

RETCODE retcode;

// Allocate memory for ODBC Environment handle
SQLAllocEnv (&hEnv);

// Allocate memory for the connection handle
SQLAllocConnect (hEnv, &hDBC);

// Connect to the data source "szDSN" using userid and password.
retcode = SQLConnect (hDBC, szDSN, SQL_NTS, szUID, SQL_NTS, szPasswd,
SQL_NTS);

if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
// Allocate memory for the statement handle
retcode = SQLAllocStmt (hDBC, &hStmt);

// Prepare the SQL statement by assigning it to the statement
handle
retcode = SQLPrepare (hStmt, szSqlStr, sizeof (szSqlStr));

// Execute the SQL statement handle
retcode = SQLExecute (hStmt);

// Project only column 1 which is the models
SQLBindCol (hStmt, 1, SQL_C_CHAR, szModel, sizeof(szModel),
&cbModel);

// Get row of data from the result set defined above in the
statement
retcode = SQLFetch (hStmt);

// Free the allocated statement handle
SQLFreeStmt (hStmt, SQL_DROP);

// Disconnect from datasource
SQLDisconnect (hDBC);
}

std::cout << retcode << "\n";

// Free the allocated connection handle
SQLFreeConnect (hDBC);

// Free the allocated ODBC environment handle
SQLFreeEnv (hEnv);
system("PAUSE");
return EXIT_SUCCESS;
}

Aug 28 '05 #1
3 9934
mike wrote:
trying the following code to test SQL connection to MS SQL server using
machine DNS name.

receiving errors:
[linker error] undefined reference to 'SQLAllocEnv@4'
[linker error] undefined reference to 'SQLAllocConnect@8'
(etc. for all SQL function calls in the code)


This is off-topic here. Try an MSSQL group.

It looks like you're missing a library in your link phase.
Aug 28 '05 #2
This is actually a well known mingw problem with DLLs, and its
relatively simple to fix. People who use MySQL know this problem well:

http://www.emmestech.com/software/cy...43/moron1.html

http://mywebpage.netscape.com/yongweiwu/stdcall.htm

http://dev.mysql.com/doc/mysql/en/wi...compiling.html

http://lists.trolltech.com/qt-intere...ad00014-0.html

see ya
Paul

Aug 29 '05 #3
I was able to figure it out based on the sources you referenced. Thank
you very much.

Aug 30 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by yopwojtek | last post: by
2 posts views Thread by yopwojtek | last post: by
11 posts views Thread by DJJ | last post: by
8 posts views Thread by Dominic Martin | last post: by
12 posts views Thread by Remco Groot Beumer | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.