1

I have a problem when I want to link a library to my Qt project. When I try to include an external library (libnodave.lib) in Qt Creator and try to build it, the following error occurs.

main.obj:-1: Fehler: LNK2019: unresolved external symbol __imp_daveSetDebug referenced in function main

I'm pretty sure that I included all needed files in my project and the .pro file. I used the "Add Library" wizard to add the library. After no success with Qt Creator, I created a minimal example with Visual Studio. When I include all the needed files to the VS project, I can build and run it without errors. So I think that there must be a problem with Qt Creator linking the library. I also tried the Qt-Visual-Studio-Add-in, but there, the same error occurs.

Here are my minimal examples with the library I want to include.

In the Visual Studio example, I added the library path, the include path, and the name of the library to the project properties. It works.

I hope you can help me with my problem.

EDIT:
I want to use the library to get some data from a S7-300 SPS device.

The following code is the minimal example from Qt Creator.

#include <QCoreApplication>
#include <QDebug>
#include <nodave.h>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    daveInterface *di;
    daveSetDebug(daveDebugConnect); // Function of libnodave Library
    qDebug() << "Hello World";

    return a.exec();
}

This is the whole code from the Visual Studio minimal example.

#include "stdafx.h"
#include <nodave.h>


int _tmain(int argc, _TCHAR* argv[])
{
    daveInterface *di;
    daveSetDebug(daveDebugConnect);
    printf("Hello World\n");

    return 0;
}

The code is very small, so I don't think that there is an error inside. That's why I think it must be a problem with the Qt linker or something like that.

EDIT:
My .pro file.

QT       += core
QT       -= gui

TARGET = qtminimal
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app   
SOURCES += main.cpp

win32: LIBS += -L$$PWD/../libnodave-0.8.5/win/ -llibnodave

INCLUDEPATH += $$PWD/../libnodave-0.8.5
DEPENDPATH += $$PWD/../libnodave-0.8.5
Wandering Fool
  • 2,170
  • 3
  • 18
  • 48
ChrisGm
  • 41
  • 1
  • 7
  • 1
    `libminimal (21MB)` not sure I wanna download this just to spend a day while looking where is your problem. Please add to the question your using of the library. Simple easy code-snippet. Don't add full project, just a [Self, short, correct (compilable) example](http://sscce.org/) – VP. Aug 10 '15 at 12:42
  • Show your `.pro` file. – VP. Aug 10 '15 at 13:01
  • Try to correct `-llibnodave` to `-lnodave`. – VP. Aug 10 '15 at 13:07
  • I changed it from "-llibnodave" to "-lnodave" but then there is an error that the linker can't find "nodave.lib" which is correct, because the lib is named "libnodave.lib". If I change the name from the lib to "nodave.lib", I have the same error as before. – ChrisGm Aug 10 '15 at 13:14
  • Okay, I just guessed that windows's qmake still respect library naming conventions, looks like it's not. Change it back to `-llibnodave`. – VP. Aug 10 '15 at 13:17
  • Try to clean/run qmake/build sequence then. – VP. Aug 10 '15 at 13:18
  • Are you using the same compiler/linker in both settings? Did you also use the same compiler to build the dll? – Blito Aug 10 '15 at 13:22
  • That's what I do every time when I try to include the library. – ChrisGm Aug 10 '15 at 13:22
  • @Blito I didn't built the dll by myself but I after reading the docs I think that it was build with the Visual Studio tools. I'm not really sure whether the compuler/linkers have the same settings in QtCreator and VS, because I don't get that much information out of QtCreator. The resulting qmake call is: qmake.exe D:\T2000_2\VS\qtminimal\qtminimal.pro -r -spec win32-msvc2013 "CONFIG+=debug" – ChrisGm Aug 10 '15 at 13:27
  • You can see it by going into Projects mode > Manage Kits (top left) and see what kit your project is using (probably Default) and which compiler is used by the Default kit. I saw [this thread](http://stackoverflow.com/a/3714112/3790945) that says that you need the `.dll.a` files at link time if you're using MinGW. – Blito Aug 10 '15 at 13:40
  • My QtCreator uses the "Desktop Qt 5.4.2 MSVC2013 64bit" kit. I think your linked thread could help me a lot but first I need to understand how this `__declspec (dllimport)` really works and what it does. I'm not sure whether I really understood what this prefix does to my library and why the `__imp_` appears. – ChrisGm Aug 10 '15 at 14:21

1 Answers1

3

The problem was that the Qt project is 64bit and the library I want to include is only 32bit. So I downloaded the 32bit version of Qt and now it works. I found the mistake, when I tried to build only the minimal example with libnodave, without any 64bit Qt libraries.

By creating a new Qt project in VS2013, with this workaround and adding the libnodave library afterwards I could change whether it should be a 64bit or 32bit build. By choosing the 32bit build, the Qt library creates errors but not the libnodave lib. When I choose 64bit build, only libnodave creates the errors.

I hope it is useful for someone else.

ChrisGm
  • 41
  • 1
  • 7