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.
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).
Re: How do I add a -c flag to the qmake?
Quote:
Originally Posted by
ChristianEhrlicher
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?
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 :)
Re: How do I add a -c flag to the qmake?
Quote:
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.
Re: How do I add a -c flag to the qmake?
Quote:
Originally Posted by
d_stranz
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.
Re: How do I add a -c flag to the qmake?
Quote:
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.
Re: How do I add a -c flag to the qmake?
Quote:
Originally Posted by
d_stranz
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.