3

I have a compiler (PGI) that does not support

#pragma once

but the library (thrust) I would like to include uses them.

Is there a workaround for this problem?

Hossein Narimani Rad
  • 31,361
  • 18
  • 86
  • 116
user1928546
  • 143
  • 1
  • 1
  • 5
  • I don't know how much good or bad my answer is considered here in SO, so I put it just as a comment: I would write a program or script which would scan the library's directory and generate the standard guard. On Linux-like systems you usually do not have right to change installed files (and I even wouldn not recommend to), so I would create a copy, just for the project. –  Apr 20 '15 at 17:43
  • Yet another reason to use `#ifndef` header guards. – 3Dave Dec 02 '16 at 22:36

2 Answers2

2

You could use guardonce to convert the #pragma once statements to standard #ifndef ... include guards.

The following worked for me:

cd /tmp
git clone https://github.com/thrust/thrust.git
git clone https://github.com/cgmb/guardonce.git
cd guardonce
git checkout v2.0.0
python -m guardonce.once2guard -r "/tmp/thrust/thrust/"

This creates the include guards in every thrust header file:

 git diff /tmp/thrust


--- a/thrust/adjacent_difference.h
+++ b/thrust/adjacent_difference.h
@@ -19,7 +19,8 @@
  *  \brief Compute difference between consecutive elements of a range
  */

-#pragma once
+#ifndef ADJACENT_DIFFERENCE_H
+#define ADJACENT_DIFFERENCE_H

. . .
cgmb
  • 4,284
  • 3
  • 33
  • 60
m.s.
  • 16,063
  • 7
  • 53
  • 88
1

Well, macros (and therefore #pragma) are handled by the preprocessor (cpp, not to be mistaken with c++ extension), so theoretically you could try using a preprocessor that supports #pragma, and then build the resulting code with your compiler.

Teyras
  • 1,262
  • 11
  • 22