Game Development Community

ACK! Linker errors.

by Andrew Dubinsky · in Torque Game Engine · 12/28/2001 (9:24 am) · 2 replies

Ok, I am having a problem that I cannot work out. I have tried everything I can think of & cannot get this to work. I must call the function SQLConnect in sql.h, it's part of the ODBC libs.

When I use this class (without the CONOBJECT) in a main() it compiles and runs fine. When I include the macros, it dies.

The error on compile that I get is:
odbcQuery.obj : error LNK2001: unresolved external symbol _SQLConnect@28
../example/torqueDemo_DEBUG.exe : fatal error LNK1120: 1 unresolved externals

Can anyone help on this one?

Here is my odbcQuery.h file:

#ifndef _ODBCCLASS_H
#define _ODBCCLASS_H
#include "platform/platform.h"
#include "console/console.h"
#include "console/consoleTypes.h"
#include "console/simBase.h"
#include "windows.h"
#include "sql.h"
#include "sqlext.h"
#include "sqltypes.h"


class MyWrapper : public SimObject {
	typedef SimObject Parent;

public:
	DECLARE_CONOBJECT (MyWrapper);
	void myfunc();

protected:
	SQLHENV     m_henv;	// Environment Handle
	SQLHDBC     m_hdbc;   // database connection handle
	SQLRETURN   m_retcode; // General return code holder for ODBC calls
	bool 		m_bIsConnected; // to see if we are connected to datasource
	const char* DSource;
	const char* UName;
	const char* PWord;

};

inline SQLRETURN  SQL_API SQLConnect(SQLHDBC ConnectionHandle,
           SQLCHAR *ServerName, SQLSMALLINT NameLength1,
           SQLCHAR *UserName, SQLSMALLINT NameLength2,
           SQLCHAR *Authentication, SQLSMALLINT NameLength3);


inline void MyWrapper::myfunc() {

S32  sqlresult = 0;
sqlresult = SQLConnect(m_hdbc, (SQLCHAR*) DSource, SQL_NTS,(SQLCHAR*) UName, SQL_NTS,(SQLCHAR*) PWord, SQL_NTS);

}



#endif

Here is my odbcQuery.cc file:

#ifndef _ODBCCLASS_CC
#define _ODBCCLASS_CC
#include "odbcQuery.h"


IMPLEMENT_CONOBJECT (MyWrapper);

ConsoleMethod (MyWrapper, myfunc, void, 1, 1, "MyWrapper.myfunc()")
{
	MyWrapper* pThis= dynamic_cast<MyWrapper*> (object);
	pThis->myfunc();
}

#endif

#1
12/28/2001 (6:30 pm)
Looks like you are not adding a library that is necessary for the final link step. Probably a sql or odbc library.
#2
12/28/2001 (6:47 pm)
Since it's a link error, it probably is just the missing library. You'll have to add it to the project, or to the list of libraries to link.