0

Minimal example:

// file: main.cpp
#include "pch.h"

int main()
{
    std::cout << "test" << std::endl;
    return 0;
}

--

// file: pch.h
#include <iostream>

Works fine and as expected if I compile this with

g++ pch.h
g++ main.cpp -Winvalid-pch

However once I change the last line to:

g++ main.cpp -fopenmp -Winvalid-pch

usage of the precompiled header is disabled:

warning: pch.h.gch: not used because `_REENTRANT' is defined [-Winvalid-pch]

How can I still use precompiled headers while linking to OpenMP? Why does the _REENTRANT define conflict with using a precompiled header at all?

user1709708
  • 1,557
  • 2
  • 14
  • 27

1 Answers1

0

You must generate .pch and compile sources with identical flags. -fopenmp implies #pragma omp and -pthread.

g++ -fopenmp pch.h
g++ main.cpp -fopenmp -Winvalid-pch

Or at least

g++ -pthread pch.h
g++ main.cpp -fopenmp -Winvalid-pch
273K
  • 29,503
  • 10
  • 41
  • 64