Undefined refence to "main"
-
wrote on 11 Dec 2019, 16:18 last edited by
Hello,
I'm trying to build a QT project but i'm getting
"/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/Scrt1.o: In function_start': (.text+0x20): undefined reference to
main'"Here is the structure of my project :
├── MainPro.pro
├── MainPro.pro.user
├── app
│ ├── app.pro
│ └── main.cpp
├── default.pri
├── src
│ ├── src.pro
│ ├── algorithms
│ │ ├── AlgorithmsFiles.cpp
│ ├── data_models
│ │ ├── data_models.cpp
│ │ ├── data_models.h
│ ├── data_models.o
│ ├── data_structures
│ │ ├── data_structures.cpp
│ │ ├── data_structures.h
│ ├── data_structures.o
│ ├── widgets
│ │ ├── widgetsFiles.h
│ │ ├── widgetsFiles.cpp
│ └── writing.o
└── test
│ ├── main.cpp
│ └── test.proAnd here is my .pro files :
default.pri :
INCLUDEPATH += ../src
SRC_DIR = ../srcMainPro.pro :
TEMPLATE = subdirsSUBDIRS =
src
app \app.depends = src
OTHER_FILES += default.pri
src.pro :
TEMPLATE = app
TARGET = src
INCLUDEPATH += .
QT += widgetsHEADERS += algorithms/AlgorithmsFiles.h
widgets/widgetsFiles.h
SOURCES += algorithms/AlgorithmsFiles.h
widgets/widgetsFiles.hThanks in advance
-
Hi,
You tell in your src.pro that the template is an application however, you don't provide any
main
function hence the error.If you want to reuse what you have in src in your
app
then you should make it a library and link to that library. -
wrote on 11 Dec 2019, 16:51 last edited by
Hello SGaist and thanks for your help,
Unfortunately I don't get what I should do precisely from your message. This application works as is on an other computer I'm just trying to rebuild it on a different environment. -
Then you should explain what you are currently expecting to build from that
src
project. -
wrote on 11 Dec 2019, 17:03 last edited by
I'm trying to build an executable which is an interface using widgets. Sorry if my answers are not clear I usually uses cmake and not qmake so I'm not used to those .pro files and this structure of project.
-
Well, if you are used to cmake, you can continue using it. There's no need to switch over to qmake especially since Qt 6 build system will be cmake.
You can find here the CMake manual for Qt projects.
However, if you really want to use qmake, then from the structure you are showing it seems that you would like to have:
- One application project which is
app
- One library project which is
src
(and that you are currently trying to build as an app)
Based on the test folder, it seems that you would like to do some unit testing (which is very good) so do you want to test your application or your library ?
- One application project which is
-
wrote on 18 Dec 2019, 15:23 last edited by
Hello SGaist,
I think I need to give you more detail about the project. So I have a first computer where this project is build as if (so with the src part building as an application and not as a library) using QT creator. On this computer we just load the project by opening MainPro.pro, compute it and launch it inside QT creator.
Now on my computer I'm trying to do the same thing. The test folder is indeed a unit testing used to test so algorithms from the src part. In QT creator i get some errors so I tried first to compile outside using qmake. I'll try to solve those errors directly inside Qt creator as compiling outside of it seemed to be a bad idea. I'll let you know if I can find what s wrong.
Thanks again for your help
-
wrote on 18 Dec 2019, 15:39 last edited by
It seems that the issue might just be cause by the fact dataChanged is not recognize, I tried to add QT+=core in my .pro files but it doesn't solve the issue
-
wrote on 18 Dec 2019, 15:52 last edited by
So in some files I have a line :
emit dataChanged(index,index, {Qt::DisplayRole, Qt::EditRole});
and the dataChanged function doesn't seem to accept the third argument -
wrote on 18 Dec 2019, 16:03 last edited by
Additionnally I get :
no matching function for call to ‘SolutionPoolModel::connect(SolutionPoolModel*, void (QAbstractItemModel::)(const QModelIndex&, const QModelIndex&), SolutionPoolModel::SolutionPoolModel(ParametersSet, QObject*)::<lambda(const QModelIndex&, const QModelIndex&, const QVector<int>&)>)’
connect(this, &SolutionPoolModel::dataChanged, [this](const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles){Q_UNUSED(topLeft) Q_UNUSED(bottomRight) Q_UNUSED(roles) this->updateMakespanBoundaries();}); ^
-
Additionnally I get :
no matching function for call to ‘SolutionPoolModel::connect(SolutionPoolModel*, void (QAbstractItemModel::)(const QModelIndex&, const QModelIndex&), SolutionPoolModel::SolutionPoolModel(ParametersSet, QObject*)::<lambda(const QModelIndex&, const QModelIndex&, const QVector<int>&)>)’
connect(this, &SolutionPoolModel::dataChanged, [this](const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles){Q_UNUSED(topLeft) Q_UNUSED(bottomRight) Q_UNUSED(roles) this->updateMakespanBoundaries();}); ^
wrote on 18 Dec 2019, 18:24 last edited by JonB@R-griset
Although these can be addressed, do you know what version of Qt, and possibly what version of which compiler, this code has been developed using? -
Additionnally I get :
no matching function for call to ‘SolutionPoolModel::connect(SolutionPoolModel*, void (QAbstractItemModel::)(const QModelIndex&, const QModelIndex&), SolutionPoolModel::SolutionPoolModel(ParametersSet, QObject*)::<lambda(const QModelIndex&, const QModelIndex&, const QVector<int>&)>)’
connect(this, &SolutionPoolModel::dataChanged, [this](const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles){Q_UNUSED(topLeft) Q_UNUSED(bottomRight) Q_UNUSED(roles) this->updateMakespanBoundaries();}); ^
@R-griset said in Undefined refence to "main":
void (QAbstractItemModel::)(const QModelIndex&, const QModelIndex&),
This is Qt4 ... you mix Qt4 and Qt5 include files.
-
wrote on 26 Dec 2019, 11:31 last edited by
-
wrote on 26 Dec 2019, 12:29 last edited by
-
Select the correct qmake for the correct Qt5 kit under 'Qt versions'
-
wrote on 26 Dec 2019, 12:44 last edited by
Hello Christian Ehrlicher and thanks for helping
Ok i changed the kit but now i'm getting back to my initial issue which I encountered outside of Qt creator : the undefined reference to main :(
13:35:55: Running steps for project anchorage...
13:35:55: Configuration unchanged, skipping qmake step.
13:35:55: Starting: "/usr/bin/make"
cd src/ && ( test -e Makefile || /usr/lib/x86_64-linux-gnu/qt5/bin/qmake /home/d07876/Desktop/Ancrage/Code\ interface\ graphique\ ancrage/UI_11_05/src/src.pro -spec linux-g++-64 CONFIG+=debug CONFIG+=qml_debug -o Makefile ) && /usr/bin/make -f Makefile
make[1]: Entering directory '/home/d07876/Desktop/Ancrage/Code interface graphique ancrage/build-anchorage-QT5-Debug/src'
g++ -m64 -o src heuristics.o longest_paths.o manual_modification.o metaheuristics.o resource_flow_computation.o resource_flow_modifications.o data_models.o data_structures.o resource_flow.o parsing.o writing.o central_widget.o central_widget_solution_tab.o gantt_view.o mainwindow.o parameters_bar.o parameters_edition_dialog.o resource_view.o sidebar.o sidebar_list.o solution_pool_view.o moc_data_models.o moc_central_widget.o moc_central_widget_solution_tab.o moc_gantt_view.o moc_mainwindow.o moc_parameters_bar.o moc_parameters_edition_dialog.o moc_resource_view.o moc_sidebar.o moc_sidebar_list.o moc_solution_pool_view.o -L/usr/X11R6/lib64 -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread
/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/Scrt1.o: In function_start': (.text+0x20): undefined reference to
main'
Makefile:228: recipe for target 'src' failed
make[1]: Leaving directory '/home/d07876/Desktop/Ancrage/Code interface graphique ancrage/build-anchorage-QT5-Debug/src'
Makefile:43: recipe for target 'sub-src-make_first' failed
collect2: error: ld returned 1 exit status
make[1]: *** [src] Error 1
make: *** [sub-src-make_first] Error 2
13:35:56: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project anchorage (kit: QT5)
When executing step "Make"
13:35:56: Elapsed time: 00:01. -
Hello Christian Ehrlicher and thanks for helping
Ok i changed the kit but now i'm getting back to my initial issue which I encountered outside of Qt creator : the undefined reference to main :(
13:35:55: Running steps for project anchorage...
13:35:55: Configuration unchanged, skipping qmake step.
13:35:55: Starting: "/usr/bin/make"
cd src/ && ( test -e Makefile || /usr/lib/x86_64-linux-gnu/qt5/bin/qmake /home/d07876/Desktop/Ancrage/Code\ interface\ graphique\ ancrage/UI_11_05/src/src.pro -spec linux-g++-64 CONFIG+=debug CONFIG+=qml_debug -o Makefile ) && /usr/bin/make -f Makefile
make[1]: Entering directory '/home/d07876/Desktop/Ancrage/Code interface graphique ancrage/build-anchorage-QT5-Debug/src'
g++ -m64 -o src heuristics.o longest_paths.o manual_modification.o metaheuristics.o resource_flow_computation.o resource_flow_modifications.o data_models.o data_structures.o resource_flow.o parsing.o writing.o central_widget.o central_widget_solution_tab.o gantt_view.o mainwindow.o parameters_bar.o parameters_edition_dialog.o resource_view.o sidebar.o sidebar_list.o solution_pool_view.o moc_data_models.o moc_central_widget.o moc_central_widget_solution_tab.o moc_gantt_view.o moc_mainwindow.o moc_parameters_bar.o moc_parameters_edition_dialog.o moc_resource_view.o moc_sidebar.o moc_sidebar_list.o moc_solution_pool_view.o -L/usr/X11R6/lib64 -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread
/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/Scrt1.o: In function_start': (.text+0x20): undefined reference to
main'
Makefile:228: recipe for target 'src' failed
make[1]: Leaving directory '/home/d07876/Desktop/Ancrage/Code interface graphique ancrage/build-anchorage-QT5-Debug/src'
Makefile:43: recipe for target 'sub-src-make_first' failed
collect2: error: ld returned 1 exit status
make[1]: *** [src] Error 1
make: *** [sub-src-make_first] Error 2
13:35:56: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project anchorage (kit: QT5)
When executing step "Make"
13:35:56: Elapsed time: 00:01.@R-griset please remove all build artifacts and build again.
Regards
-
In your src.pro you tell qmake that you want to build an application but you do not provide a main() function there (I would guess)
-
In your src.pro you tell qmake that you want to build an application but you do not provide a main() function there (I would guess)
wrote on 26 Dec 2019, 12:55 last edited by@Christian-Ehrlicher but this exact code work perfectly on an other computer so there should be a setting which doesn't need a main function there
-
@R-griset said in Undefined refence to "main":
so there should be a setting which doesn't need a main function there
Yes, don't tell qmake that you want to create an application... an application needs a main.
4/35