0

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:

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

Tiana987642
  • 696
  • 2
  • 10
  • 28

1 Answers1

1

You are using subdirs template wrong. It should not contain anything, but SUBDIRS and sometimes CONFIG += ordered. Also your project model is a bit complicated. You should try something simplier first, without libraries and subprojects.

Good example of subdirs project: How to use QMake's subdirs template?

Update

I'll explain a bit. Minimal changes you need to do in your project in order it to compile & link:

  1. remove SOURCES = $$PWD/Presenter/main.cpp line from WiringClone.pro
  2. add CONFIG += ordered to WiringClone.pro and View.pro
  3. remove config \ line from WiringClone.pro (this is the one that caused the original link error)
  4. order subprojects. WiringClone.pro: Utilities Model View Presenter, View.pro: Logic GUI

But, even after all these changes you'll have to solve an unsolvable problem: your Utilities library depends on your Model library, but your Model depends on your Utilities. Linking doesn't work this way. Cyclical dependencies are not allowed. That's why I recommend you to loose all your libraries and write a simple solid executable first.

Community
  • 1
  • 1
Amartel
  • 4,248
  • 2
  • 15
  • 21
  • You mean the root project? I add `SOURCES = $$PWD/Presenter/main.cpp` after the linker complains about `undefined reference to `main'`. But it ain't work. – Tiana987642 Apr 30 '15 at 11:05
  • And I already did a small project similar to this but every code files in the same directory. So I want to take a few step more: re-structure ... – Tiana987642 Apr 30 '15 at 11:15
  • First step from here is to move files into different directories and add them to project like this: 'SOURCES += src/model/model.cpp src/view/view.cpp' etc. Second step is to learn how to use `pri` files. Third step is to write a subdir, containing only 2 projects - one library and one executable, which uses it. And only after doing all this you sould try somethig as complicated, as your exaple. Yes, life is pain ^_^. – Amartel Apr 30 '15 at 11:31
  • Thank, it works :D Do you have any suggestion about cyclical dependencies between `Utilities` and `Model`? I think I should merge `Utilities` into methods of `WiringModel`. – Tiana987642 Apr 30 '15 at 11:44
  • 1
    Yes, you should definitely merge something into something else. For example `Utilities` into `Model`. – Amartel Apr 30 '15 at 11:52