4

I am using pragma once in my .cpp files.

However I am always having a warning #pragma once in main file.

How to disable it? I am using GCC 5.1.0.

lapots
  • 12,553
  • 32
  • 121
  • 242
  • Possible duplicate of [Remove #pragma once warnings](http://stackoverflow.com/questions/23135538/remove-pragma-once-warnings) – Pyves Sep 11 '16 at 08:19
  • 1
    I need this too, I filled a bug with gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89808 – binarez Mar 24 '19 at 13:18

2 Answers2

1

I am not sure there is a way.

Putting #pragma once in the main file isn't actually useful. #pragma once it used in a header to prevent the header from being included more than once.

Note that #pragma once is unavoidably slower than using the straightforward and portable header guard style:

#ifndef something_h
#define something_h
... header text here
#endif

So I would recommend simply not using it ever.

Tom Tromey
  • 21,507
  • 2
  • 45
  • 63
  • Well...In order to do things faster for now I don't use headers and just create classes inside namespaces in .cpp files. So in order to prevent redefinition errors I added `#pragma` directive. – lapots Jul 17 '15 at 13:12
  • 1
    [Some folks disagree with you](https://stackoverflow.com/a/787539/4019986). – NanoWizard Jun 08 '18 at 00:53
  • it's not slow, in bug report there is used symbolic link instead of files, which results in another inclusion. So it's not slow, it's buggy test application. – TarmoPikaro Jun 24 '19 at 03:42
-1

Use the -w compile option to remove this warning.

e.g. gcc -w -o <output file> <input file(s)>

Ravi Tiwari
  • 946
  • 8
  • 17