PDA

View Full Version : Qt sub-project undefined reference to `main'



unias
30th April 2015, 11:32
I'm learning The Model-View-Presenter (MVP) Pattern with Qt and have the follow example (https://drive.google.com/file/d/0B2ifIdidcU5fY09fMDZyOU4zaTA/view?pli=1). I can build it and run it from build folder, but can't debug it due to the error:


.../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

ChrisW67
30th April 2015, 11:57
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.

unias
30th April 2015, 12:25
The SOURCES entry in the top-level PRO file is not useful. The subdirs project type does not build any code itself.

I added
SOURCES = $$PWD/Presenter/main.cpp after the linker complains about
undefined reference to main'. But it ain't work :p


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?



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

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.

d_stranz
30th April 2015, 16:22
.../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?

Radek
30th April 2015, 18:01
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:


TEMPLATE = subdirs

and directives controlling the order or making the subprojects. Either the "depends" directives


<build next>.depends = <build first>

for example


testapp.depends = library

(more such directives can be present) or the "ordered" directive:


CONFIG += ordered

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.


TEMPLATE = subdirs

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.

unias
1st May 2015, 09:21
Thank ChrisW67, d_stranz and Radek for your suggestion, I was able to fix it, just remove
config from the root pro file