Results 1 to 6 of 6

Thread: Qt sub-project undefined reference to `main'

  1. #1
    Join Date
    Sep 2014
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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:

    Qt Code:
    1. .../glibc-2.19/sysdeps/x86_64/start.S:118: error: undefined reference to `main'
    2. error: collect2: error: ld returned 1 exit status
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

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

  3. #3
    Join Date
    Sep 2014
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt sub-project undefined reference to `main'

    The SOURCES entry in the top-level PRO file is not useful. The subdirs project type does not build any code itself.
    I added
    Qt Code:
    1. SOURCES = $$PWD/Presenter/main.cpp
    To copy to clipboard, switch view to plain text mode 
    after the linker complains about
    Qt Code:
    1. undefined reference to main'
    To copy to clipboard, switch view to plain text mode 
    . But it ain't work
    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
    Qt Code:
    1. unix:!macx: LIBS += -L$$DEPLOYMENT_PATH -lUtilities
    2.  
    3. INCLUDEPATH += $$PWD/../Utilities
    4. DEPENDPATH += $$PWD/../Utilities
    To copy to clipboard, switch view to plain text mode 

    Till now, still can't debug it. But I can run it manually in the deployment folder.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,316
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt sub-project undefined reference to `main'

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

  5. #5
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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:
    Qt Code:
    1. TEMPLATE = subdirs
    To copy to clipboard, switch view to plain text mode 
    and directives controlling the order or making the subprojects. Either the "depends" directives
    Qt Code:
    1. <build next>.depends = <build first>
    To copy to clipboard, switch view to plain text mode 
    for example
    Qt Code:
    1. testapp.depends = library
    To copy to clipboard, switch view to plain text mode 
    (more such directives can be present) or the "ordered" directive:
    Qt Code:
    1. CONFIG += ordered
    To copy to clipboard, switch view to plain text mode 
    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.
    Qt Code:
    1. TEMPLATE = subdirs
    To copy to clipboard, switch view to plain text mode 
    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.

  6. #6
    Join Date
    Sep 2014
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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
    Qt Code:
    1. config
    To copy to clipboard, switch view to plain text mode 
    from the root pro file

Similar Threads

  1. undefined reference
    By deepakswaroop in forum Newbie
    Replies: 1
    Last Post: 2nd March 2011, 06:46
  2. Undefined reference
    By eekhoorn12 in forum Qt Programming
    Replies: 2
    Last Post: 6th January 2011, 15:45
  3. undefined reference
    By digidas in forum Newbie
    Replies: 9
    Last Post: 19th May 2010, 13:04
  4. undefined reference
    By jayreddy in forum Qt Programming
    Replies: 1
    Last Post: 20th November 2009, 13:45
  5. Undefined reference to crt
    By derektaprell in forum Installation and Deployment
    Replies: 0
    Last Post: 20th October 2009, 08:34

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.