Qt sub-project undefined reference to `main'
I'm learning The Model-View-Presenter (MVP) Pattern with Qt and have the follow example. I can build it and run it from build folder, but can't debug it due to the error:
Code:
.../glibc-2.19/sysdeps/x86_64/start.S:118: error: undefined reference to `main'
error: collect2: error: ld returned 1 exit status
I can't figure out what's wrong? A quick Google search brings not much information. PS: I use OpenSUSE 13.1 with Qt 4.8
Re: Qt sub-project undefined reference to `main'
You are presenting a linker error, so you have not yet built the program.
The SOURCES entry in the top-level PRO file is not useful. The subdirs project type does not build any code itself.
The config folder contains nothing to be built and should not be listed in the subdirs project. No PRO file is needed in that folder.
In order to build Presenter you need to tell it where to find the built Utilities library (LIBS) and ensure Utilities is built first (Use CONFIG += ordered with subdirs).
When I fix those things the program builds.
Re: Qt sub-project undefined reference to `main'
Quote:
The SOURCES entry in the top-level PRO file is not useful. The subdirs project type does not build any code itself.
I added
Code:
SOURCES = $$PWD/Presenter/main.cpp
after the linker complains about
Code:
undefined reference to main'
. But it ain't work :p
Quote:
The config folder contains nothing to be built and should not be listed in the subdirs project. No PRO file is needed in that folder.
I tried to delete the .pro file but I can't. How to do this? Did you do this with QtCreator?
Quote:
In order to build Presenter you need to tell it where to find the built Utilities library (LIBS) and ensure Utilities is built first (Use CONFIG += ordered with subdirs).
I added this to Presenter.pro
Code:
unix:!macx: LIBS += -L$$DEPLOYMENT_PATH -lUtilities
INCLUDEPATH += $$PWD/../Utilities
DEPENDPATH += $$PWD/../Utilities
Till now, still can't debug it. But I can run it manually in the deployment folder.
Re: Qt sub-project undefined reference to `main'
Quote:
.../glibc-2.19/sysdeps/x86_64/start.S:118:
Looks like you are building with a 64-bit compiler. Are you linking to 64-bit libraries?
Re: Qt sub-project undefined reference to `main'
Where did you added the main.cpp? A multitarget project consists of a "root" project (which you will make) and subprojects. The "root" project contains:
and directives controlling the order or making the subprojects. Either the "depends" directives
Code:
<build next>.depends = <build first>
for example
Code:
testapp.depends = library
(more such directives can be present) or the "ordered" directive:
in the later case, the subprojects will be made in the order they have been added to the project. No SOURCES directive in the main project (see Chris post).
Supposing you are using Creator, do the following:
(1) Create the root project. It will contain only one line for now.
Save.
(2) Add a subproject: Right-click the "root" project directory and select "Add Subproject". Select the name of the subproject (for example testapp). This will create a subdirectory "testapp". Create a profile for testapp. It must be testapp.pro, otherwise the profile won't be found. The testapp subproject is a "full sized" project containing sources (for example main.cpp) resources and other things.
(3) Add another subproject.
...
(4) Return to the root project and specify dependencies.
(5) Go to the configuration page of the Creator and select what it should make: Select "Run" and set the root project.
Re: Qt sub-project undefined reference to `main'
Thank ChrisW67, d_stranz and Radek for your suggestion, I was able to fix it, just remove from the root pro file