Question about preprocessor flags

Hi,

I’m trying to port an application that uses gcc to pgcc.

The first issue that I’m having is related to the GNU ‘-include’ flag: reading the manual the only flag I found that does something similar is the ‘-Mcpp=include:file’. However, I detected that it does not behave as I’d expect when we have more than one file to be included. Below you can find an small example:

//melon.h
typedef int MELON;

// t1.h
#define MELON T1
#include "melon.h"
#undef MELON
void foo();

// t2.h
#define MELON T2
#include "melon.h"
#undef MELON
void bar();

// main.c
int main();

When I preprocess main.c using the following command:
pgcc -E main.c -Mcpp=include:t1.h -Mcpp=include:t2.h -o-

typedef int T1;
PREPRO-W-0221-Redefinition of symbol MELON (./t2.h: 1)
typedef int T2;

void bar();
void foo();

int main();

Which is not what I was expecting: I expected that I would get first the content of t1.h (typedef int T1; void foo();) , the content of t2.h (typedef int T2; void bar(); ) and finally the content of main.c (int main();).

I saw that in pgc++ you have another flag called ‘–preinclude’ that does exactly what I want. Unfortunately, this flag does not exist in C :(

here is another way to get the result I want? Am I missing something?

Thanks!,

Sergi

EDIT: I forgot to mention that I was using pgcc 18.4-0 64-bit

Hi Sergi,

I’ve not used -Mcpp=include before so unfortunately don’t know what’s wrong there.

Though, are you able to instead include the headers in main.c?


% cat main.c

#include "t1.h"
#include "t2.h"

// main.c
int main();
% pgcc -E main.c -I.
...

This will work as expected.

-Mat

Hi Mat,

Sorry for the delay, I completely forgot this topic.

Unfortunately, I cannot modify the application: those headers are included by our source-to-source compiler when a specific flag is used.
What we are trying to do is to define PGI compilers as the native compiler of our source-to-source compiler.

Any other idea? I could preprocess using a different preprocessor/compiler, although it is not always a good idea.

Thanks!,
Sergi

How about using the C++ compiler with the “–c” flag to tell it that the source is a C file? Then you can use --preinclude.

% pgc++ main.c --preinclude=t1.h --preinclude=t2.h -c --c 
%

I’ll try that, thank you for your answer!

Sergi