我已经四处搜寻试图解决这个错误的帖子,但在任何情况下,我已经在做他们建议的。无法解析的外部符号公开__thiscall只在调试模式下
我的编译输出:
main.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall KeyLogger::~KeyLogger(void)" ([email protected]@[email protected]) referenced in function _main
main.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall KeyLogger::KeyLogger(void)" ([email protected]@[email protected]) referenced in function _main
debug\AccipioKeyDemo.exe:-1: error: LNK1120: 2 unresolved externals
我知道,这是说,我已经定义了键盘记录器的构造函数和析构函数,但尚未实现,但实际上我拥有一切实现。
的main.cpp
#include <QCoreApplication>
#include "keylogger.h"
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
KeyLogger k;
return a.exec();
}
keylogger.h
#ifndef KEYLOGGER_H
#define KEYLOGGER_H
#include <Windows.h>
class KeyLogger {
public:
KeyLogger();
~KeyLogger();
void start();
void stop();
private:
HHOOK hook;
LRESULT CALLBACK intercept(int code, WPARAM wparam, LPARAM lparam);
};
#endif // KEYLOGGER_H
keylogger.cpp
#include "keylogger.h"
#include <QDebug>
KeyLogger::KeyLogger() : hook(NULL) {
hook = SetWindowsHookEx(WH_KEYBOARD_LL, intercept, NULL,0);
if (hook == NULL) {
qDebug() << "HOOK FAILED";
} else {
qDebug() << "HOOK SUCCESS";
}
}
KeyLogger::~KeyLogger() {
}
void KeyLogger::start() {
qDebug() << "start";
}
void KeyLogger::stop() {
qDebug() << "stop";
}
LRESULT CALLBACK KeyLogger::intercept(int code, WPARAM wparam, LPARAM lparam) {
qDebug() << "Key Pressed";
return CallNextHookEx(hook, code, wparam, lparam);
}
QT Pro的配置
#-------------------------------------------------
#
# Project created by QtCreator 2013-10-10T19:58:51
#
#-------------------------------------------------
QT += core
QT -= gui
TARGET = AccipioKeyDemo
CONFIG += console
CONFIG -= app_bundle
LIBS += user32.lib
TEMPLATE = app
SOURCES += main.cpp \
keylogger.cpp
HEADERS += \
keylogger.h
为什么你需要在KeyLogger.h中包含'#include'? –
billz
,因为HHOOK宏是在Windows.h中定义的 – arnm
您对错误理解的指示是正确的。你需要发布更多关于你的构建环境的细节。你在使用make吗? qmake的?视觉工作室?发布项目文件! –