1

Following on from this question: Getting list of available ODBC data sources in my Qt application

When I compile the code in the answer I get an "unresolved external symbol" error.

In my MainWindow I have hadded the following includes:

#include <windows.h>
#include <tchar.h>
#include <iostream>
#include <sql.h>
#include <sqlext.h>
#include <sqlucode.h>

and have created a function like so:

int listDataSources()
{
    // Get an Environment handle
    SQLHENV hEnv = SQL_NULL_HENV;
    SQLRETURN ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hEnv);

    if( ! SQL_SUCCEEDED(ret) ) {}

    SQLFreeHandle(SQL_HANDLE_ENV, hEnv);
    return 0;
}

The errors reported area:

image showing errors

The sql.h file in use has the following section:

image of sql.h code

This is definitely the file being used and ODBCVER is greater than 0x0300 as if I place a #define MIKEDIDTHIS = 777 after the ODBCVER test it gets set and I can dDebug() it.

ODBCVER is set ealrier in the file with this code:

#ifndef ODBCVER
#define ODBCVER 0x0380
#endif

I'm using Qt Creator version 3.4.2 and Qt 5.5.0 (MSVC 2013 32 bit)

Can you walk me through the steps I should take in trying to find the cause of the problem?

Community
  • 1
  • 1
Michael Vincent
  • 1,620
  • 1
  • 20
  • 46
  • You have a linker error. That is something totally different than a compiler error. Usually the compilation was executed successfully before you can even receive a linker error. – Bowdzone Oct 13 '15 at 14:12
  • @Bowdzone Thank you. Am I right in thinking its a link from the sql.h file that is missing? And if so, what should it be linked to, and where? – Michael Vincent Oct 13 '15 at 14:16
  • @NathanOliver I have changed the question somewhat - I have looked at the answer you linked to, but even having read that, I still don't know how to resolve my issue. So I've asked for help to walk me through the steps I need to take. – Michael Vincent Oct 13 '15 at 14:31
  • 1
    @Michael Vincent: I tested it with the QTCreator, you need to link against odbc32.lib. For me, this works by adding a line like this to the .pro file: LIBS += -L"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib" -lodbc32 No idea why I do not have to specify this lib if I link things together using visual studio. Also no idea if you need to install some additional stuff to get this "Microsoft SDK". – erg Oct 14 '15 at 08:01
  • @erg Thank you for testing with QTCreator. My lib file was in a different location ( C:\Program Files (x86)\Windows Kits\8.0\Lib\win8\um\x86 ), but other than that it seems to work - at least an exe is created and runs and, most importantly, produces a list of the data sources on my pc. Thank you for your help. – Michael Vincent Oct 14 '15 at 08:29
  • @Michael: Your welcome. I was wrong, also the visual studio projects links against odbc32.lib (had made no sense at all if there would have been no need to link). I just looked at the wrong entry in the still-not-so-handy visual studio settings dialog. – erg Oct 14 '15 at 09:29

0 Answers0