LNK2019 error using multiple source files
Hello community,
I can't run my hello world program, I get LNK2019 error.
main.cpp
Code:
#include <QCoreApplication>
#include "hello.h"
int main(int argc, char *argv[])
{
Hello *hi = new Hello();
return app.exec();
}
hello.h
Code:
#ifndef HELLO_H
#define HELLO_H
class Hello{
public:
Hello();
};
#endif // HELLO_H
hello.cpp
Code:
#include <iostream>
class Hello{
public:
Hello(){
std::cout << "hello world" << std::endl;
}
};
myproject.pro
Code:
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
hello.cpp \
main.cpp
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
HEADERS += \
hello.h
It works fine without creating Hello object.
Re: LNK2019 error using multiple source files
Did you run qmake again after changing your .pro file to add the hello.* entries?
Re: LNK2019 error using multiple source files
You define your class Hello a second time in hello.cpp