简体   繁体   中英

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:

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM