If you include the QtWidgets file in .cpp, then when checking the syntax of clang (clang_complete, vim), an error is noted, during the transition we will go to the qglobal.h file where it says:

#if !defined(QT_BOOTSTRAPPED) && defined(QT_REDUCE_RELOCATIONS) && defined(__ELF__) && \ (!defined(__PIC__) || (defined(__PIE__) && defined(Q_CC_GNU) && Q_CC_GNU >= 500)) # error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\ "Compile your code with -fPIC (-fPIE is not enough)." #endif 

What does this mean and why does clang see an error at this moment?

Closed due to the fact that off-topic participants VTT , 0xdb , nick_n_a , ߊߚߤߘ , Edward 12 Jun '18 at 13:30 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - VTT, 0xdb, nick_n_a, Edward
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 3
    The clang "sees" an error, since the condition in #if true, then the #error directive, which the developers have placed in this .h file, is triggered. Probably you should follow their recommendations "Compile your code with -fPIC (-fPIE is not enough)." - avp
  • @avp is understandable, but the check, as I already wrote, occurs when checking the syntax, not compiling ... In general, how to eliminate it? - Andrej Levkovitch
  • @avp, that's it, figured out how to fix this problem! Thanks for pointing out about -fPIC - I’ve seen it before, but I hadn’t thought of putting it in the option to the compiler for syntax checking) - Andrej Levkovitch

1 answer 1

In general, expressing gratitude to avp, I want to leave this answer if someone has a similar problem when programming in vim. To solve it, you just need to specify clang that the check should be done with the -fPIC option. To do this, simply include in the file .clang_complete, which is contained in this directory line

 -fPIC 

After that, the error will disappear.

  • In fact, if you want to figure it out, then start by saying that the -fPIC option tells the compiler to do position-independent code (and is usually used when creating shared libraries (.so, .dll)). And vim (text editor) has nothing to do with this problem. - avp
  • @avp Listen, because the question clearly states: "when checking the clang syntax (clang_complete, vim)" - tobish: the syntax is checked in the vim editor using the clang_complete plugin, which in turn uses clang. Accordingly, in order for clang to see that you need to use -fPIC here, we specify in the configuration file what to use -fPIC. Perhaps you did not understand, but the problem is not at the compilation stage !!! And check! - Andrej Levkovitch
  • one
    In fact, you are right. I just never use the likes of a'la IDE stuff - avp
  • @avp Well, yes, this approach is not popular, although, as for me, it is very convenient. At least I have not yet encountered situations where you could not do without a full-fledged IDE. - Andrej Levkovitch
  • I understand you. Probably at the initial stage, IDE hints are useful. Then they just become not needed. ( however, I started with punched cards (even before the AC terminals), when the IDE term was not invented, so I can be wrong) - avp