Results 1 to 8 of 8

Thread: How do I add a -c flag to the qmake?

  1. #1
    Join Date
    Jul 2021
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default How do I add a -c flag to the qmake?

    Ubuntu 18.04 OS
    Qt 5.12.5
    Pure C++ application

    When compiling an app done by others, I am experiencing over 1800 'multiple definition of ' errors.
    After scouring the internet, I understand the ideas behind the error.

    The problem is all the solutions to the error are already in place! and still the error occurred.
    (#ifndef INCLUDED_A_H
    #define INCLUDED_A_H

    class A { };

    #endif)

    There was a suggestion of using the -c flag to cure the problem:

    Your compilation rule is missing a -c flag:

    %.o: %.cpp $(HEADERS)
    g++ -std=c++11 $< -c -o $@

    Without it, each source file will get compiled/linked into a complete executable rather than just stopping after the compilation step to create a simple object file. Your link step then tries to link those already-linked executables and crashes due to the multiple symbol declarations.

    Please show me how to include the -c flag. I tried 'CONFIG += -c -o' in the .pro file to no effect.

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    552
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How do I add a -c flag to the qmake?

    I would rather fix the code instead adding a hack (which I would guess does not work).

  3. #3
    Join Date
    Jul 2021
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How do I add a -c flag to the qmake?

    Quote Originally Posted by ChristianEhrlicher View Post
    I would rather fix the code instead adding a hack (which I would guess does not work).
    Thank you for your suggestion, but could you please show me how to include the -c flag using the .pro file?

  4. #4
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    552
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How do I add a -c flag to the qmake?

    No - I neither use qmake nor add any hacks to fix a compilation issue like yours

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,021
    Thanks
    280
    Thanked 818 Times in 807 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: How do I add a -c flag to the qmake?

    could you please show me how to include the -c flag using the .pro file?
    You could ask Google like I did.

    But Christian is right - something else is wrong with your project, and adding a hack to fix it is the wrong way to go. Fix the project and you won't need magic.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  6. #6
    Join Date
    Jul 2021
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How do I add a -c flag to the qmake?

    Quote Originally Posted by d_stranz View Post
    You could ask Google like I did.

    But Christian is right - something else is wrong with your project, and adding a hack to fix it is the wrong way to go. Fix the project and you won't need magic.
    The this is the thing...this isn't "my" project, it is an app done by many contributors using Gnu Make with Vim and Tcl scripts.

    There are 12 "main" functions also(!); haven't encountered anything like it since I use IDEs.

    Qt Creator doesn't handle such a software config too well apparently; thus the multiple definitions. These multiple definitions don't happen using the above-mentioned tool chain since they use certain compiler settings since the inception of their project.

    I "did" use google and have already tried several suggestions to no avail. There is one solution I haven't tried involving modifying a config file deep in the Qt Creator folder hierarchy because I'd rather modify compiler flags within the project .pro file. Modifying a config file directly suggests a global compiler flag change for all projects, and is not desired.

    Using the "Gnu Make with Vim with Tcl scripts" tool chain is not desirable even though the app was developed thus, and runs using them. Certain flags are set that are hard to set using Qt Creator.

    Instead of "fixing" a giant app that I didn't create using Qt Creator (and I must say such a monstrosity would probably not ever be created using Qt Creator), I simply want to step though it in the debugger to glean which parts I want to cannibalize. It looks like I'll have to just visually decipher the flow of the code instead.

    This is the only reason I was looking for a way to set a compiler flag, not to escape fixing "my own code".

    I do appreciate your comments.

    SamQ

    P.S.- I tried compiling the app using Cevelop IDE, and got many errors anyway but no "multiple definition" errors; interesting. BTW, Qt Creator is far superior to Cevelop.

  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,021
    Thanks
    280
    Thanked 818 Times in 807 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: How do I add a -c flag to the qmake?

    There are 12 "main" functions also(!); haven't encountered anything like it since I use IDEs.
    Then clearly, obviously, the "project" was not meant to be compiled and linked the way you are trying to do it. There are at least 12 separate sub-projects here (12 executables plus possibly dynamic or static libraries), each of which must be compiled and linked as a separate unit.

    It is possible that the main() functions are part of a unit testing framework, where when a certain pre-processor #define is present (or not), it compiles and links an executable that tests that part of the project.

    In any case, if the "giant project" was not designed for compiling with QtCreator, then why are you trying to do that? If it uses Gnu Make or some other build tool, use that. But adding a qmake hack to force 12 separate entrees to be cooked in the same pot is not the way to do it.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  8. #8
    Join Date
    Jul 2021
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How do I add a -c flag to the qmake?

    Quote Originally Posted by d_stranz View Post
    Then clearly, obviously, the "project" was not meant to be compiled and linked the way you are trying to do it. There are at least 12 separate sub-projects here (12 executables plus possibly dynamic or static libraries), each of which must be compiled and linked as a separate unit.

    It is possible that the main() functions are part of a unit testing framework, where when a certain pre-processor #define is present (or not), it compiles and links an executable that tests that part of the project.

    In any case, if the "giant project" was not designed for compiling with QtCreator, then why are you trying to do that? If it uses Gnu Make or some other build tool, use that. But adding a qmake hack to force 12 separate entrees to be cooked in the same pot is not the way to do it.
    You are absolutely right! Thank you.

Similar Threads

  1. How can we add -O2 flag into .pro file?
    By learning_qt in forum Qt Programming
    Replies: 3
    Last Post: 4th November 2009, 08:15
  2. Flag storing
    By bismitapadhy in forum Qt Programming
    Replies: 1
    Last Post: 24th June 2009, 05:26
  3. how to set WDestructiveClose Flag
    By amitkhanna in forum Newbie
    Replies: 4
    Last Post: 17th June 2007, 16:20
  4. using Q::desktop flag
    By nupul in forum Newbie
    Replies: 1
    Last Post: 30th April 2006, 14:58
  5. Replies: 5
    Last Post: 13th March 2006, 20:22

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.