Welcome, Guest. Please Login or Register
Arduino IDE for Visual Studio
When Logging a Support Issue in the Forum, please ensure you have also:-
  • Enabled vMicro > Compiler > Show Build Properties and Verbose
  • Re-Compile your program with these settings enabled
Save the new Output to a Text File and....
Support requests without the output above may be impossible to answer, so please help us to help you
  HomeSearch Tutorials & Wiki visualmicro.com LoginHelpRegister  
Page Index Toggle Pages: 1
Send Topic Print
#pragma once doesn't work (Read 79 times)
Evgeny Zhekaus
Junior Member

Posts: 26
#pragma once doesn't work
Oct 23rd, 2019 at 3:31pm
I’ve got a quite strange problem. Today, I start work with updating VS to 16.3.6.

After that I’ve got the following error:
Compiling 'Arduino_GSM_Relay' for 'ATmega328P (Nano 57600)'

gsm_action.h:10: In file included from
MyApp.cpp:21: from

GSMClass.h: 17:7: error: redefinition of 'class ZhGSMClass
   class ZhGSMClass \\ **
Error compiling project sources

MyApp.h:3: In file included from
MyApp.cpp:4: from
GSMClass.h:17: note  previous definition of class ZhGSMClass
   class ZhGSMClass \\ **
Build failed for project 'Arduino_GSM_Relay'


Here is the code:
#pragma once

// #ifndef GSMCLASS_H
// #define  GSMCLASS_H

#ifdef ARDUINO
#include <Arduino.h>

#include <SoftwareSerial.h>

class ZhGSMClass;

typedef void (*SmsParserCb)(ZhGSMClass* pGSM, const char* pcMsg, const char* pcNum);
typedef int (*CallCb)(const char* pcNum);

class ZhGSMClass // **

As you see, there is `#pragma once`. And I am certain I’ve got the only file with such a name and the only class definition.
I can’t see such a problem with ordinary C++ projects. That makes me think that the problem relates to vMicro after last VS update.

The problem is gone when I add a classic header guard.
#ifndef GSMCLASS_H
#define  GSMCLASS_H

Back to top
« Last Edit: Oct 23rd, 2019 at 3:39pm by Visual Micro »  
IP Logged
Visual Micro

Posts: 10568
United Kingdom
Re: #pragma once doesn't work
Reply #1 - Oct 23rd, 2019 at 3:41pm
Visual Micro and Visual Studio do not have any connection to how the code is compiled. We simply run the respective tool chain .exe to compile each file.

So this sounds like you are using a different or older tool chain. The information requested in the yellow box above will show you the compilation so you can see the .exe that runs the compile for each file.
Back to top
IP Logged
Page Index Toggle Pages: 1
Send Topic Print