所以我在Visual中编写了一些类(它们在VS中工作),并将它们添加到Qt中。当我做一个指向一个类的指针时,一切都好。但是,如果我创建这个类,就会得到2个“未解决的外部符号”错误,大约有2个方法(类中只有2个)。其中一个看起来是这样的:
mainwindow.obj:-1: error: LNK2001: unresolved external symbol "protected: virtual void __cdecl SRT::processInputLine(class Subtitles &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?processInputLine@SRT@@MEAAXAEAVSubtitles@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
下面是这个方法的声明:
virtual void processInputLine(Subtitles& subtitles, const string& line) throw(TimesOverlap) override;
类字幕继承向量,其中字幕是另一个类。
如果我将定义粘贴到这个文件中(我知道我不应该这样做),我只会得到与这些方法使用的其他类相同的错误,而不是前面的两个错误。Qt没有正确链接.cpp文件吗?为什么只有在创建类时才会出现此链接错误,而不是在此之前?有什么想法吗?谢谢!
Edit1:这是我的.pro文件:
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += main.cpp\
mainwindow.cpp \
Subtitles.cpp \
MicroDVD.cpp \
MPlayer.cpp \
Subtitle.cpp \
TimeStamp.cpp \
SRT.cpp \
SubtitleIO.cpp
HEADERS += mainwindow.h \
globalVariables.h \
Exceptions.h \
MicroDVD.h \
MPlayer.h \
Subtitle.h \
Subtitles.h \
TimeStamp.h \
SRT.h \
SubtitleIO.h
FORMS += mainwindow.ui
DISTFILES += \
SubtitleEditor.pro.user
如您所见,其中包括.h和.c文件。我在试着弄清楚如何运行qmake..。
发布于 2017-05-01 18:02:23
我在试着弄清楚如何运行qmake..。
在控制台上使用qmake.exe yourProFile.pro
。或者,所有IDE都提供了一种运行qmake的方法。如果您正在使用Qt,请调用Build > Run qmake
。
https://stackoverflow.com/questions/43722332
复制相似问题