Skip to content

Open command prompt in a directory for use with gcc

Today I thought I would be clever and make a cmdhere shortcut even for my GCC installation. Well, easier said than done. I have spent whole forenoon trying to figure this one out. It took quite few trials and tests along with one and another hair straw to figure out how much I really suck when it comes to batch files J

Here is the problem: I have NVidias Tegra distribution of Android tools, for working with Android. Packaged with distribution is collection of Unix tools in form of Cygwin which comes with an older installation of GCC (3.x.x). For playing around and testing some new features of latest C++ standard, I prefer to have as updated version of GCC as possible, which at time I write this is 4.8.1. Maybe GCC folks have updated older versions as well with newer libraries and features, I don’t know; but shiny new stuff is always fun so I went for the bleeding edge and installed MINGW GCC version 4.8.1.

Obviously I can have only one installation of GCC in my PATH so in order to keep my masochistic tendencies hidden (really guys is anybody expected to type all of this at command line: x86_64-w64-mingw32-gcc-4.8.1.exe :-)) I had to found some workaround. I could go for some smart naming schemes or links, but I decided to do same thing as Visual Studio creators do: to create a separate batch file to initiate environment for use with GCC.

In case of GCC it is enough to just prepend GCC bin directory to PATH. So I could simply take my VSCmdHere install and search and replace names and paths. I actually come on idea to make a script that will create an .inf file along with the batch file and install it for me based on the GCC install directory. That way when I install new GCC I can just move my batch file and update my context menu to shiny new compiler.

Few hours later and quite many hair straw less I finally figured it out! What caused the permanent hair loss were all the substitutions that are done during batch execution. It took a while to figure out how many escape characters and quote signs are needed in what place. I won’t discuss implementation details much; basics are to get path, and then create gccvars.bat and gcchere.inf files. The script asks for admin privileges which are needed in order to modify the register. Uninstalling is done through Add/Remove programs as usually.

Batch file is available for download and should be saved in top-level directory of GCC (same as bin,lib etc ..). When installed it will create a file called gccvars.bat in same directory and add an entry to start command prmpt with GCC in path in right-click menu for directory and drive.


Post a Comment

Your email is never published nor shared. Required fields are marked *