There is a * .h file with the following code:

#ifndef CORECOMMANDS_H #define CORECOMMANDS_H #pragma once #include <QString> #include <QStringList> struct MassageDataIn{ QString operationId; QStringList names; QStringList values; }; //袟邪锌褉芯褋 斜邪蟹芯胁褘褏 锌邪褉邪屑械褌褉芯胁 褟写褉邪 const MassageDataIn cmdSetupRequest(){ MassageDataIn massageData; massageData.operationId = "12"; return massageData; } //袟邪锌褉芯褋 褋芯褋褌芯褟薪懈褟 褟写褉邪 const MassageDataIn cmdSync(){ MassageDataIn massageData; massageData.operationId = "11"; return massageData; } 

This file was written in the console application and worked without any errors. After creating the console application, it became necessary to use it in the QWidget application already. When I try to compile the project at the initial stage (I just created a standard QWidget project and connected this and several more files, after copying it from the console project), I get an error:

14: error: multiple definition of 'cmdSetupRequest ()' UI \ corecommands.h: 14: first defined here UI \ debug \ core.o: -1: In function `Z7cmdSyncv ':

On the forum I read that adding inline and extern solve this problem and it really is. BUT! Why is it possible to do without them in the console application, but not in QWidget ? If you still can correct these errors without adding inline and extern how can this be done.

ps pragma once in all * .h files

    1 answer 1

    The definition of non- inline functions must be in the implementation file, i.e. *.cpp . When the header file is connected to different implementation files, it turns out that different modules have the same functions. Linker is getting worse and he says an error like this:

    multiple definition of `cmdSetupRequest () '

    Well, there is not enough #endif in your file. Yes, and the simultaneous use of different include-guard somehow over the top though.

    • #endif is simply not copied. And why then in the console application, everything is working fine? - Madisson
    • @Madisson is visible because it is included in only one module (because there are no others, where the corresponding #include present) and conflicts do not occur. - 伪位蔚蠂慰位蠀蟿
    • Clear, thanks for the help. - Madisson
    • @Madisson please. - 伪位蔚蠂慰位蠀蟿