简体   繁体   中英

qt creator qt5.1 vs2010 linker error when using static library

i have a problem when i try to use a static library which was compiled with vs2010 in qt creater with qt 5.1. I'm using qt5.1. which was compiled with/for the vs2010 compiler.

The source for my simple library look as follows:

Lib_Test.h

#pragma once
#include <iostream>

class Lib_Test
{
  public:
    Lib_Test(void);
    ~Lib_Test(void);

    void HelloTest();
};

Lib_Test.cpp

#include "Lib_Test.h"

Lib_Test::Lib_Test(void)
{
}

Lib_Test::~Lib_Test(void)
{
}

void Lib_Test::HelloTest()
{
  std::cout << "Hello World!";
}

This two files are compiled into my "Lib_Test.lib". I copied the lib and the header file to "C:/Qt/" to simplify the library calls. My qt project file (for a c++ console application):

QT       += core
QT       -= gui

TARGET = Lib_Test_Qt
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app

SOURCES += main.cpp

INCLUDEPATH += C:/Qt
DEPENDPATH += C:/Qt

win32:CONFIG(release, debug|release): LIBS += -LC:/Qt/
win32:CONFIG(release, debug|release): LIBS += -lLIB_Test

And finally the main.cpp

#include <QCoreApplication>
#include <Lib_Test.h>

int main(int argc, char *argv[])
{
      QCoreApplication a(argc, argv);

      Lib_Test *lb = new Lib_Test();
      lb->HelloTest();

      return a.exec();
}

When i try to build the project in Qt Creator i get the following error message

main.obj:-1: Fehler:LNK2019: unresolved external symbol "public: void __thiscall Lib_Test::HelloTest(void)" (?HelloTest@Lib_Test@@QAEXXZ) referenced in function _main
main.obj:-1: Fehler:LNK2019: unresolved external symbol "public: __thiscall Lib_Test::Lib_Test(void)" (??0Lib_Test@@QAE@XZ) referenced in function _main
debug\Lib_Test_Qt.exe:-1: Fehler:LNK1120: 2 unresolved externals

When i declare the HelloTest method as a static method and try to call it without creating an instance of Lib_Test i get a similar error Message

main.obj:-1: Fehler:LNK2019: unresolved external symbol "public: static void __cdecl Lib_Test::HelloTest(void)" (?HelloTest@Lib_Test@@SAXXZ) referenced in function _main
debug\Lib_Test_Qt.exe:-1: Fehler:LNK1120: 1 unresolved externals

What am i missing? Can someboody help? It's really frustrating right now :/.

Edit:

I tried DUMPBIN /SYMBOLS Lib_Test.lib in the msvs2010 console and all i get is:

Microsoft (R) COSS/PE Dumper Version 10.00.40210.01
Copytight (C) Microsoft Corporation. All right reserved


Dump of file Lib_Test.lib

File Type: LIBRARY

Does that mean that my library is somehow empty?? :/

In your qmake files, change win32:CONFIG(release, debug|release): LIBS += -C:/Qt/ -lLib_Test win32:CONFIG(release, debug|release): PRE_TARGETDEPS += C:/Qt/Lib_Test.lib

To

win32:CONFIG(release, debug|release): LIBS += -LC:/Qt/
win32:CONFIG(release, debug|release): LIBS += -lLib_Test

Or

win32:CONFIG(release, debug|release): LIBS += -LC:/Qt/
win32:CONFIG(release, debug|release): LIBS += -l_Test

I think one of them should work. And don't forget to go to Build menu, then Run qmake.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM