Results 1 to 3 of 3

Thread: Unresolved error when compiling

  1. #1
    Join Date
    Oct 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    5

    Default Unresolved error when compiling

    I have a bit of a problem when compiling my application which complains with an LNK2019: unresolved error.
    Qt Code:
    1. LNK2019: unresolved external symbol "public: void __thiscall MainWindow::showMessageBox(class QString)
    To copy to clipboard, switch view to plain text mode 
    Basically my application is split into modules to make it easier to add/remove features and one of those modules cannot 'see' another file.

    The project structure is as follows:
    Qt Code:
    1. Project
    2. ---- bin
    3.  
    4. ---- modules
    5. ---- ---- FooModule
    6. ---- ---- ---- FooModule.h
    7. ---- ---- ---- FooModule.cpp
    8.  
    9. ---- src
    10. ---- ---- MainWindow.h
    11. ---- ---- MainWindow.cpp
    To copy to clipboard, switch view to plain text mode 
    The compiled files from both the modules folder and src folder end up in the bin folder after a successful compilation.
    FooModule is actually a separate project within the main project folder and is compiled as a shared library (i.e. dll, as I'm on Windows).
    MainWindow successfully creates a new FooModule and passes itself into FooModule's constructor.
    At this point FooModule knows about MainWindow's header file but can't see the implementation file as when I try to call any of MainWindow's methods from FooModule's constructor I get the unresolved error about the method I just tried to call.

    I'm guessing I just haven't quite got the correct info in the .pro files:
    Qt Code:
    1. // Project.pro
    2.  
    3. QT += core gui
    4. TARGET = Project
    5.  
    6. TEMPLATE = subdirs
    7. CONFIG += ordered debug
    8.  
    9. SUBDIRS += modules/FooModule \
    10. src \
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. // FooModule.pro
    2. TARGET = FooModule
    3. TEMPLATE = lib
    4.  
    5. DEFINES += FOOMODULE_LIBRARY
    6.  
    7. SOURCES += FooModule.cpp
    8.  
    9. HEADERS += FooModule.h\
    10. FooModule_global.h
    11.  
    12. INCLUDEPATH += ../../src
    13.  
    14. DESTDIR += ../../bin
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. // src.pro
    2. QT += core gui
    3.  
    4. TARGET = Project
    5.  
    6. TEMPLATE = app
    7.  
    8. CONFIG += ordered debug
    9.  
    10. INCLUDEPATH += ../modules/FooModule
    11.  
    12. SOURCES += main.cpp\
    13. MainWindow.cpp \
    14.  
    15. HEADERS += MainWindow.h
    16.  
    17. LIBS += -L../bin -lFooModule
    18.  
    19. DESTDIR += ../bin
    To copy to clipboard, switch view to plain text mode 


    Can anyone see where I have gone wrong?
    Thanks
    Last edited by cgyan1; 3rd July 2012 at 21:56.

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3
    Thanked 127 Times in 126 Posts

    Default Re: Unresolved error when compiling

    you have a circular reference. redesign/refactor to remove it.

    foomodule should not be needing to know anything about users of itself.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. The following user says thank you to amleto for this useful post:

    cgyan1 (4th July 2012)

  4. #3
    Join Date
    Oct 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    5

    Default Re: Unresolved error when compiling

    Thanks, yes, I see what you mean now.
    I think I've probably got my concepts muddled a little bit, this is the first time I've made and tried to use my own library.
    I guess the idea of a library is a self contained unit that knows how to perform a task but has no idea how it gets used in a specific application i.e. like a database library that knows how to connect, open, query etc but it is your specific application that calls those methods.

    What my thinking was to create the different modules independently from each other, passing in the Main Window to their constructors, and therefore no module has any knowledge or dependency on any other part of the program (other than the MainWindow). Each module can then look after after itself and update the MainWindow etc. This way, any module can be added or removed with ease.

    I think I'm on the right lines but trying to compile each module as a dynamic library was probably the wrong approach. It would have been nice to have been able to complete a module, compile it, and then forget about it and keep the core application lightweight, also not having everything compile (all modules) when I Build or Run. Some of the Run compile times are getting a little silly now.

    Thanks again for the help.

Similar Threads

  1. error LNK2001: unresolved external symbol _IID_ID3DXEffec tStateManager
    By Tusharsankhala in forum Installation and Deployment
    Replies: 0
    Last Post: 16th May 2012, 19:16
  2. Replies: 1
    Last Post: 8th November 2011, 16:28
  3. Replies: 3
    Last Post: 29th April 2011, 10:13
  4. Replies: 1
    Last Post: 25th October 2008, 20:18
  5. Replies: 16
    Last Post: 23rd May 2008, 11:12

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.