I have looked around for posts trying to solve this error but in every case I am already doing what they have suggested.
My compile output:
main.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall KeyLogger::~KeyLogger(void)" (??1KeyLogger@@QAE@XZ) referenced in function _main
main.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall KeyLogger::KeyLogger(void)" (??0KeyLogger@@QAE@XZ) referenced in function _main
debug\AccipioKeyDemo.exe:-1: error: LNK1120: 2 unresolved externals
I know that this is saying that I have the KeyLogger constructor and destructor defined but not implemented but I actually do have everything implemented.
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 config
#-------------------------------------------------
#
# 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
#include <Windows.h>
in KeyLogger.h? – billzkeylogger.cpp
to the project. The linker is not aware of its existence. – Igor Tandetnik