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.
我有一个问题,当我尝试使用一个静态库,在qt creater与qt 5.1使用vs2010编译。我正在使用qt5.1。这是用vs2010编译器编译的。
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):
这两个文件被编译到我的“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
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 :/.
我错过了什么? someboody可以帮忙吗?现在真的很令人沮丧:/。
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?? :/
这是否意味着我的图书馆有点空? :/
1 个解决方案
#1
0
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。
#1
0
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。