Results 1 to 6 of 6

Thread: compilation issues: multiple includes?

  1. #1
    Join Date
    Feb 2008
    Location
    Honolulu, HI
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question compilation issues: multiple includes?

    Hello all,

    I'm having problems compiling my code under Linux using Qt Creator (Qt 4.6).

    In particular, I have a header file "m.h" like the following:
    Qt Code:
    1. #ifndef M_H
    2. #define M_H
    3. #include "data.h"
    4.  
    5. #include <QtGlobal>
    6. #include <QString>
    7.  
    8. namespace MYNAMESPACE {
    9. class M : public QObject
    10. {
    11. Q_OBJECT
    12. ....
    13. }
    14. #endif
    To copy to clipboard, switch view to plain text mode 

    With a corresponding implementation "m.cpp":
    Qt Code:
    1. #include "m.h"
    2.  
    3. namespace MYNAMESPACE {
    4. ....
    5. }
    To copy to clipboard, switch view to plain text mode 

    data.h contains constants and helper functions, and also includes QtGlobal and QString.

    Now, when I try to compile this, I get errors like these:

    m.o: In function M:
    [path to qtglobal.h]/qtglobal.h: 1361: multiple definition of `MYNAMESPACE::M::M()'
    [path to qtglobal.h]/qtglobal.h: 1361: first defined here

    It then proceeds to complain that every single function in m.cpp is already defined in m.cpp (identical line numbers).

    I have no idea whatsoever. Why would it claim that my own function/class is previously defined in qtglobal.h, I am even using my own namespace? And then, why do I get errors that complain that a method defined in one file was perviously defined in the same file? This error repeats through my entire program with all functions that I have written. Is it wrong to include QtGlobal or what am I missing?

    I think I also should mention that I get a lot of warnings about my Makefile that look like this:

    Makefile:[line number]: warning: ignoring old commands for target 'moc_m.cpp'
    Makefile:[line number]: warning: ignoring old commands for target 'm.o'


    Any help would be greatly appreciated.

    Thanks,
    Stephan

  2. #2
    Join Date
    Dec 2009
    Posts
    19
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: compilation issues: multiple includes?

    Quote Originally Posted by sfabel View Post
    In particular, I have a header file "m.h" like the following:
    Qt Code:
    1. ...
    2. namespace MYNAMESPACE {
    3. class M : public QObject
    4. {
    5. Q_OBJECT
    6. ....
    7. #closing bracket?
    8. }
    9. #endif
    To copy to clipboard, switch view to plain text mode 
    Did you miss closing bracket ('}') in the marked position? Or just missed it when posting?
    From my experience with C++, such strange errors usually happen when there is a syntax error somewhere, for example missing bracket, semi-colon or smt like that.

    Quote Originally Posted by sfabel View Post
    Makefile:[line number]: warning: ignoring old commands for target 'moc_m.cpp'
    Makefile:[line number]: warning: ignoring old commands for target 'm.o'
    But most likely it seems that moc (qt's meta-object compiler) doesn't run when building for some reason, so C++ compiler tries to compile Qt-specific stuff and fails.

    P.S. If data.h includes QtGlobal and QString there is no need to include them in m.h.

  3. #3
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: compilation issues: multiple includes?

    isn't it more like this (keeping .h the same) :

    Qt Code:
    1. #include "m.h"
    2.  
    3. using namespace MYNAMESPACE ;
    4.  
    5. // aso..
    To copy to clipboard, switch view to plain text mode 

    because indeed you declare your namespace twice. or am I wrong ?

  4. #4
    Join Date
    Nov 2009
    Location
    Siauliai, LT
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: compilation issues: multiple includes?

    not sure, but maybe semicolon is missing?
    I came. I saw. I clicked.

  5. #5
    Join Date
    Dec 2009
    Posts
    19
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: compilation issues: multiple includes?

    Quote Originally Posted by totem View Post
    isn't it more like this (keeping .h the same) :

    Qt Code:
    1. #include "m.h"
    2.  
    3. using namespace MYNAMESPACE ;
    4.  
    5. // aso..
    To copy to clipboard, switch view to plain text mode 

    because indeed you declare your namespace twice. or am I wrong ?
    Semantically that's the same, since namespace itself cannot be declared; by putting statements inside namespace block you just tell compiler that they belong to that namespace. Namespaces are just syntactic sugar after all (they are not translated to assembly code, and used only to distinguish methods and classes with the same name during compilation).
    After all, you can just add "MYNAMESPACE::" before class name when implementing methods, that'll give the same result too.

    My bet is that sfabel's problem lies in the fact that files generated by moc are not being compiled.
    Qt Code:
    1. Makefile:[line number]: warning: ignoring old commands for target 'moc_m.cpp'
    To copy to clipboard, switch view to plain text mode 
    This line tells that make ignored command for 'moc_m.cpp' processing, which is a file generated by moc most probably.

  6. #6
    Join Date
    Nov 2009
    Location
    Siauliai, LT
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: compilation issues: multiple includes?

    i meant semicolon in .h file not cpp one. can you provide .h file contents?
    I came. I saw. I clicked.

Similar Threads

  1. Focus issues / Setting multiple focus
    By ComputerPhreak in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2007, 06:09

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.