0

当我尝试在带有 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”。我将 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

这是否意味着我的图书馆是空的?:/

4

1 回答 1

0

在您的 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。

于 2013-09-23T20:53:21.203 回答