简体   繁体   English

使用静态库时,qt创建者qt5.1 vs2010链接器错误

[英]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. 我在尝试使用在qt 5.1的qt creater中使用vs2010编译的静态库时遇到问题。 I'm using qt5.1. 我正在使用qt5.1。 which was compiled with/for the vs2010 compiler. 使用vs2010编译器编译的。

The source for my simple library look as follows: 我的简单库的源代码如下:

Lib_Test.h Lib_Test.h

#pragma once
#include <iostream>

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

    void HelloTest();
};

Lib_Test.cpp 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". 这两个文件被编译到我的“ Lib_Test.lib”中。 I copied the lib and the header file to "C:/Qt/" to simplify the library calls. 我将库和头文件复制到“ C:/ Qt /”以简化库调用。 My qt project file (for a c++ console application): 我的qt项目文件(用于c ++控制台应用程序):

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 最后是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 当我尝试在Qt Creator中构建项目时,出现以下错误消息

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 当我将HelloTest方法声明为静态方法并尝试在不创建Lib_Test实例的情况下调用它时,出现类似的错误消息

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: 我在msvs2010控制台中尝试了DUMPBIN / SYMBOLS Lib_Test.lib,我得到的是:

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 在您的qmake文件中,更改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. 并且不要忘记转到Build菜单,然后运行qmake。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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