簡體   English   中英

使用靜態庫時,qt創建者qt5.1 vs2010鏈接器錯誤

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

我在嘗試使用在qt 5.1的qt creater中使用vs2010編譯的靜態庫時遇到問題。 我正在使用qt5.1。 使用vs2010編譯器編譯的。

我的簡單庫的源代碼如下:

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!";
}

這兩個文件被編譯到我的“ Lib_Test.lib”中。 我將庫和頭文件復制到“ C:/ Qt /”以簡化庫調用。 我的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

最后是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();
}

當我嘗試在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

當我將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

我想念什么? 可以幫助嗎? 現在真的很沮喪:/。

編輯:

我在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

這是否意味着我的圖書館某種程度上是空的? :/

在您的qmake文件中,更改win32:CONFIG(release,debug | release):LIBS + = -C:/ Qt / -lLib_Test win32:CONFIG(release,debug | release):PRE_TARGETDEPS + = C:/Qt/Lib_Test.lib

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

要么

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

我認為其中之一應該起作用。 並且不要忘記轉到Build菜單,然后運行qmake。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM