Sarthak
Sarthak

Reputation: 3

Trying to set up a pre-compiled header

fatal error: can't create precompiled header stdc++.h.gch: Permission denied

I'm getting the above error while using the command g++ -std=c++14 stdc++.h on windows powershell in the directory where stdc++.h is located. How do I fix this ?

Upvotes: 0

Views: 421

Answers (2)

Burak
Burak

Reputation: 2495

There are two things to consider here.

  • Administrative privilege
  • Precompiled header

The solution to the first one is easy. You are trying to make changes in a system directory. I assume the following attempt will succeed but I cannot test.

  1. Create my_pch.hpp that contains the following line in desktop or any other user directory.
    #include <stdc++.h>
    
  2. Compile the header in that directory.
    g++ -std=c++14 my_pch.hpp
    

You should get the same precompiled header.


You should ask yourself why you need a precompiled header. Answers on do we really need precompiled headers mentions about the effect of the size of the project, reduction in compile time, but facing with further problems. If you are unsure, it is advised not using them.

Upvotes: 1

whiskeyo
whiskeyo

Reputation: 914

Run Powershell as an administrator and it should work fine - you gain all permissions you need.

Upvotes: 0

Related Questions