Monday, June 6, 2022

[SOLVED] How to Precompile <bits/stdc++.h> header file in ubuntu 20.04?

Issue

Is there any way to precompile the <bits/stdc++.h> header file in ubuntu 20.04 like we can do in Windows OS so that I can execute programs faster in my Sublime text editor?

I use the FastOlympicCoding extension for fast execution, but I miss the old way of using an input-output file. I searched everywhere but didn't find any 'layman' approach to do that.


Solution

So, After having help from @TedLyngmo's answer and doing a little bit more research, I decided to answer the question myself with more clear steps.

PS: This answer will be more relatable to those who are using sublime with their custom build file and are on Linux OS (Ubuntu).

  1. You need to find where stdc++.h header file is present, so open the terminal and use the command:

    find /usr/include -name 'stdc++.h'

    Output:

    /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h

  2. Go to the above location and open the terminal there and now we are ready to precompile bits/stdc++.h header file.

  3. Use the following command:

    sudo g++ -std=c++17 stdc++.h

  4. You'll observe stdc++.h.gch file is now created implying that precompiling is done.

PS: You need to use sudo as we need root privileges when g++ makes stdc++.h.gch file.

NOTE: Here as I was using the c++17 version in my custom build file so I mentioned c++17, you can use whatever version you are using.

It worked perfectly for me so I hope it helps you too!



Answered By - princebansal_
Answer Checked By - Robin (WPSolving Admin)