Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt creator - `multiple definition of qMain` error

Tags:

c++

qt

I started to work for my homework using QT creator to make the GUI, but I gt this error and I can't manage to find the reason for it, nor can I understand what it means. I suppose it sees my main function twice but I do not know why... please assist me in fixing this error:

error:

Makefile.Debug:155: warning: overriding commands for target `debug/main.o'
    Makefile.Debug:142: warning: ignoring old commands for target `debug/main.o'
    debug/main.o: In function `Z5qMainiPPc':
    D:\c++\Labs\GUI_r/../../../info/qt/Desktop/Qt/4.8.1/mingw/include/QtGui/qwidget.h:494: multiple definition of `qMain(int, char**)'
    debug/main.o:D:\c++\Labs\GUI_r/main.cpp:7: first defined here
    collect2: ld returned 1 exit status

Code:

#include <QtGui/QApplication>
#include "mainwindow.h"
#include "controller.h"
#include "StudentRepository.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    StudentRepository *stre = new StudentRepository();
    Controller *c = new Controller(stre);
    MainWindow w(c);
    w.show();

    return a.exec();
}

edit: long code removed - not the reason for the error. Check the answere it is useful.

like image 373
Bogdan M. Avatar asked Dec 07 '25 08:12

Bogdan M.


2 Answers

The reason for that linking error is because of awkawrd behaivior behalf QT creator. I had in the projectName.pro -

QT       +=    core gui

TARGET = GUI_r
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp \
    main.cpp \                   /////// Double call of main.cpp
    StudentRepository.cpp \
    controller.cpp

HEADERS  += mainwindow.h \
    controller.h \
    StudentRepository.h \
Student.h \
ui_mainwindow.h \        /////Double call of ui_mainwindow.h 
ui_mainwindow.h

FORMS    += mainwindow.ui

Thank you, i hope this post will be usefull to other new users of QTcreator.

like image 179
Bogdan M. Avatar answered Dec 08 '25 21:12

Bogdan M.


Maybe your project contains another source file with a main. Somewhere files duplicated. Check "SOURCES =" and main.cpp in your .pro file.

like image 26
0xAX Avatar answered Dec 08 '25 21:12

0xAX



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!