'gcc' is not recognized - How to make gcc/mingw work in Windows? - c

The Mingw binary installation instructions (such as these) tells me to change the PATH environment variable in Windows, in order to use the gcc/g++ etc commands anywhere. This might also be necessary for some programming IDE to find the compiler. Failing to do so yields errors such as this:
'gcc' is not recognized as an internal or external command, operable program or batch file.
How do I do this specifically in newer versions of Windows (10/11) and which path should I use?

Right-click "My Computer"/"This PC" from Windows explorer and pick properties. Alternatively Windows key + X and click "System". An "About" window appears.
Scroll down to "Advanced system settings" and click on it.
Click on the "Environment Variables" button.
Select "Path" in the window that appears and click the edit button.
Click on "Edit text" (not on "Edit"!).
Before modifying anything, I strongly recommend to copy the text there and save it in a text file for backup, so that you can restore the PATH in case of mistakes.
Write a semicolon ; at the end of the text there unless already present. Then after the semicolon add the full path to your Mingw installation's bin folder. For example ;c:\mingw_w64\bin.
Important: if you installed Mingw under for example C:\program files\mingw_w64, then the path must be ;C:\Program Files\mingw-w64\bin; without any surrounding " ... ". If using the "Edit" command available in this window, then the " ... " will get added and this may break the gcc path from working. (It just happened to me and that's the reason why I decided to write this Q&A.)
Click OK for each open window.
Reboot Windows.
Now you should be able to type gcc from the command line or use it from your programming IDE.

Alternatively, for CLI users:
Open cmd.
Type PATH.
Add the absolute path to the bin folder to it.
Place a semi-colon at the end.
Press enter.
Reboot.
And you're done.
Edit: For the full path to the bin folder:
cd your way to Mingw installation's bin folder, or alternatively, press windows key + e.
Open mingw -> bin.
Copy the full path present in the search bar.
As #Lundin said, you should first make a copy of the original PATH and save it, just in case something goes wrong.

Related

How to set default opener [duplicate]

How can I set TextMate as default text editor on Mac OS X?
I've tried it with
ln -s /Applications/TextMate.app/Contents/Resources/mate ~/bin/mate
export EDITOR='mate -w'
but that doesn't work.
Just right (or control) click a file of the type you want to change and:
"Get Info" -> "Open with:" -> (Select TextMate) -> "Change All"
The method through Finder is not practical. If you're a developer, your files likely include .profile, .gitconfig, .bashrc, .bash_profile, .htdocs, etc.
The best way to do this is in Bash (for Sublime Text 3):
defaults write com.apple.LaunchServices LSHandlers -array-add '{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.sublimetext.3;}'
For other text editors, I assume you can replace 'com.sublimetext.3' with the proper string. You could probably Google for your text editor's name + "LSHandlerContentType=public.plain-text" to figure out what your app's string would be.
For me, this changed the defaults for both Finder, and
$ open ~/.bashrc
Have you modified your shell PATH environment variable to include ~/bin? That directory is usually not included in PATH by default on OS X. It might be simpler to create the symlink in /usr/local/bin which is usually included in PATH. Try:
echo $PATH
This worked for me on OS X v10.11 (El Capitan):
defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add \
'{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.macromates.textmate.preview;}'
For TextMate 2:
defaults write com.apple.LaunchServices LSHandlers -array-add '{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.macromates.TextMate;}'
And you need to restart after that.
To change the default text editor across the board, use the aforementioned method (i.e., "Get Info" → "Open with:" → (editor of choice) → "Change All") on .txt files. Then it will be used as the default editor for any text-based file that doesn't yet have an application preference for its extension.
For instance, if you use the terminal, the command open -t will use your preferred text editor, which is whatever application is associated with .txt files. By default this is (you guessed it) TextEdit, unless you explicitly specify otherwise.
I found Replace Text Edit as the default text editor on apple.stackexchange which works really well.
For developer-type files like .gitignore, use the last option provided:
duti -s com.macromates.TextMate public.data all
Substitute your editor's CFBundleIdentifier as needed. To find it, locate the application file, right-click and choose Show Package Contents, then open Info.plist in the Contents folder. CFBundleIdentifier should be near the top...
This work on Catalina. I'll update my answer if/when I update my OS.

DOSBOX In Ubuntu: Unable to open include file 'stdio.h' [duplicate]

Whenever I compile my program, I get the error above.
If you have problems like that, first of all your TC folder put in to the C:..drive.
after completing installation open turbo c blue screen.
there is a OPTIONS > Directories ..in that you can see for option to set up path..
include directories..you can set path there now.. C:\TC\INCUDE
libraries Directories..you can set path there...C:\TC\LIB
if you want to store your output in BIN then you can set..C:\TC\BIN..otherwise you can set another path where you want to store your output..
Finally you can give OK and finished processes..
It will now work properly
Do this: Open your turboc2 folder you have tc.exe file inside, beside this file you find another file as named as ' tcinst.exe ' open it.
You will see the installation menu:
select as-- > Option > Directory > Include directory
Here you have to change the path of the directory to the path where your INCLUDE folder is located. Same way change the path to library directory also over restart your tc.exe.
Check if you have anything like those stdio.h file and other header files under INCLUDE folder and LIB folder. LIB contains some files. In my case, I had the same issue but both of these folder were blank.. good to know.
Steps:
Press: ALT + O + D (i.e. press ATL (keep pressed) and then O english character) and then D).
You'll see a popup window.
This window will have values for INCLUDE and LIB directories. The by default value for these two boxes in the popup window are: Drive leter where you installed TC... i.e. C:\ or D:\ or whatever followed by the path for INCLUDE and LIB folder. So, in my case,
INCLUDE box was set to: "C:\TC\INCLUDE" and LIB directory value box was set to: "C:\TC\LIB" (without quotes).
Steps to resolve:
Press ALT + C.
Set your current directory as C:\TC\BGI
Press ALT + O + D, and put ../INCLUDE and ../LIB in Include/Lib directory values.
and now... when you'll run your progress, you'll say thanks to me. I like the archduchess C fractal graphics that I'm running on DOS Turbo C right now. Lol.
Go to OPTIONS tab then select directories option then enter the particular path where your turbo c folder exists.
Enter the path in all the four message boxes and it would start working like it did in my case. I have TurboC3 and all the files were together in one common root folder.
Check your environment include path. The file is not in the locations pointed by that environment variable.
Well, I've been working backshift just spent about 6 hours trying to figure this out.
All of the above information led to this conclusion along with a single line in dos prompt screen, when I exited the editor, go to the dos prompt my C: drive is mounted.
I did a dir search and what I found was: the way in which I had mounted the C drive initially looked like this
mount c: /
and my dir did not list all files on the C drive only files within the turboc++ folder.
From that I had drawn the conclusion that my directories should look like:
c:\include
not
c:\turboc++\tc\include
or
c:\tc\include
The real problem was the nature in which I had mounted the drive.
Hope this helps someone.
b.mac
Since you did not mention which version of Turbo C this method below will cover both v2 and v3.
Click on 'Options', 'Directories', enter the proper location for the Include and Lib directories.
On most systems, you'd have to be trying fairly hard not to find '<stdio.h>', to the point where the first reaction is "is <stdio.h> installed". So, I'd be looking to see if the file exists in a plausible location. If not, then your installation of Turbo C is broken; reinstall. If you can find it, then you will have to establish why the compiler is not searching for it in the right place - what are the compiler options you've specified and where is the compiler searching for its headers (and why isn't it searching where the header is).
Make sure the folder with the standard header files is in the projects path.
I don't know where this is in Turbo C, but I would think there's a way of doing this.
First check whether the folder name is right or wrong since while you copying to one folder from other accidently it takes other folder address eg it take C instead of F So from OPTION>DIRECTORY change the folder name
Just Re install the turbo C++ from your Computer and install again in the Directory C:\TC\ Folder.
Again The Problem exists ,then change the directory from FILE>>CHANGE DIRECTORY to C:\TC\BIN\

Find a file by name in Visual Studio Code

How can I find a file by name in Visual Studio Code?
A Visual Studio shortcut I'm used to is CTRL+,, but it does not work here.
When you have opened a folder in a workspace you can do Ctrl+P (Cmd+P on Mac) and start typing the filename, or extension to filter the list of filenames
if you have:
plugin.ts
page.css
plugger.ts
You can type css and press enter and it will open the page.css. If you type .ts the list is filtered and contains two items.
Press Ctl+T will open a search box. Delete # symbol and enter your file name.
I believe the action name is "workbench.action.quickOpen".
It is CMD + P (or CTRL + P) by default. However the keyboard bindings may differ according to your preferences.
To know your bindings go to the "Keyboard Shortcuts" settings and search for "Go to File"
It's Ctrl+Shift+O / Cmd+Shift+O on mac.
You can see it if you close all tabs
According to this Github page, it's now a simple Cmd+F inside the File Explorer tree on Mac (and presumably Ctrl+F on Windows). Found and highlighted all the README.md files I've been working on:
file search results in vscode file explorer pane
Caveat: The tree has to be fully expanded for this to work.

How do we write a program in Command line development environment?

I have been writing my code in IDE,I just read that there also existed a Command Line Development Environment in which the code is written in DOS.I googled but found no results on how to use the command line development environment.My OS is Windows XP.I would be very thankful for your help me write the hello world program in DOS and also explain how to run it.
You simply use whatever text editor you like to create the C sourse file(s) then invoke the compiler command line(s) to compile and link the program (typically, an IDE is doing exactly that, but in a behind-the-scene manner). How the command line is invoked depends on the exact toolchain you're using.
You might also need to set up an environment for you particular compiler toolchain (the right paths and various other env variables might need set up).
For Visual C++ the environment might be set up using a batch file installed by Visual Studio:
vcvarsall x86
Invoking the compiler could be as simple as:
cl helloworld.c
or for C++ (for some reason it issues a non-fatal warning if you don't give it an option configuring details about how it should implement exceptions):
cl /EHsc helloworld.cpp
The particulars are very dependent on the compiler you're using - you should read the docs for that compiler.
Also, the options you use depend on your particular situation and needs. Scripts/batch files and/or makefile can help you manage the complexity of the options you might need to use.
DOS is not dead.... yet!
fahad
There are a number of methods by which you can enter code in DOS (see EDIT further on down).
(1) You can send keystrokes directly to a file
You do this by redirecting output to CON (the console) to a file. The only oddity of this method is that you end the 'session' by entering a CTRL-Z when you are finished.
It's basic, but this is how it goes.
Firstly, suppose you want to display "Hello World" on the screen, a simple batch file containing the following two lines is all that is required:
#echo off
echo Hello World
The '#echo off' is commonly found at the start of all batch files. It simply instructs the command interpretter NOT to display each command as it is being executed (or parsed).
One more thing before we start. Throughout this answer, I will assume your program is named 'helloworld.bat'.
Enter the following lines one after the other pressing the ENTER key at the end of each line:
copy con helloworld.bat
#echo off
echo Hello World
^Z
The '^Z' is displayed when you press the CTRL-Z key combination (don't forget to press the ENTER key as well).
When you press the ENTER key after CTRL-Z, DOS displays the familiar '1 File(s) copied' messege.
You can now execute the batch file program by simply entering the program's name like this:
helloworld
And DOS will display the following:
Hello World
It can't get any more basic than that.
(2) You can use DOS' EDIT program
This is a DOS based IDE retained from around the mid-90's. Simply enter the following command:
edit
And EDIT will open in the same DOS window. When you close EDIT, you are returned back to DOS again.
EDIT also works with your mouse.
Once EDIT opens, enter the following two lines of code:
#echo off
echo Hello World
Then, click on [File], [Save], type: 'helloworld.bat' in the "File Name" input field, use your mouse to change directories in the "Directories:" pane if you want to, then click [OK]. To return to DOS, click [File], [Exit].
EDIT version 4.5 (I think) was context-sensitive and displayed code using different colours to seperate key word, different data type, symbols etc.
(3) Use Windows' built-in Notepad
This is simple. At the command prompt, enter the following command:
notepad
And Notepad will fire up. It's a simple text editor and does the job when entering small programs.
(4) Use Notepad++. It's FREE!!
Notepad++ is the programmer's choice. It's free, full of useful features and customisable. Find it on the net by searching for "notepad++".
From your comment, "Just some knowledge so I can say that I know one way to do programming without IDE" I would say learn to write simple batch files. They can be run from Explorer but they exist as a holdover from the DOS days.
Start a command prompt window (Start->Run->'cmd'), this will open a window and show a prompt, most likely "c:\" or some other path.
Type the following command (followed by )
echo "Hello World"
You should see:
"Hello World"
c:\
Now, using whatever editor you'd like, create a text file with that command as the only line. Name the file "hello.bat". When you are at the command prompt you can execute the batch file like so:
c:\hello.bat
"Hello World"
c:\
You have now programmed using the DOS command line. For more commands and such, start with the help system.
c:\help
Which will display all the available commands for your batch file.
Microsoft has an online reference here.
DOS is dead for all practical purposes. Under Windows your options boil down to the following:
Use an IDE. Visual Studio is one example, Qt another. You can write programs for the commandline with an IDE.
Use a proper text editor, build tool and other helper tools. You might use gvim for editing code, make for building your project and git for version control. You might as well use the GNU coreutils for other helpers, or maybe even the entire cygwin package.
Bro, use gcc compiler for which write ur code in any text editor then compile ur code in windows shell or u can say command line environment.
Look!
Prompt:/> gcc source_file_name.c
This command compiles ur code,
If there is any error, u will get dispalyed with line numbers,
now, every program creates its exe file by the name a.exe by default.
To, get the output of ur program,
Prompt:/> a.exe
O/P
Hello World!
To change the name of the exe file there is also a command..

How to fix "unable to open stdio.h in Turbo C" error?

Whenever I compile my program, I get the error above.
If you have problems like that, first of all your TC folder put in to the C:..drive.
after completing installation open turbo c blue screen.
there is a OPTIONS > Directories ..in that you can see for option to set up path..
include directories..you can set path there now.. C:\TC\INCUDE
libraries Directories..you can set path there...C:\TC\LIB
if you want to store your output in BIN then you can set..C:\TC\BIN..otherwise you can set another path where you want to store your output..
Finally you can give OK and finished processes..
It will now work properly
Do this: Open your turboc2 folder you have tc.exe file inside, beside this file you find another file as named as ' tcinst.exe ' open it.
You will see the installation menu:
select as-- > Option > Directory > Include directory
Here you have to change the path of the directory to the path where your INCLUDE folder is located. Same way change the path to library directory also over restart your tc.exe.
Check if you have anything like those stdio.h file and other header files under INCLUDE folder and LIB folder. LIB contains some files. In my case, I had the same issue but both of these folder were blank.. good to know.
Steps:
Press: ALT + O + D (i.e. press ATL (keep pressed) and then O english character) and then D).
You'll see a popup window.
This window will have values for INCLUDE and LIB directories. The by default value for these two boxes in the popup window are: Drive leter where you installed TC... i.e. C:\ or D:\ or whatever followed by the path for INCLUDE and LIB folder. So, in my case,
INCLUDE box was set to: "C:\TC\INCLUDE" and LIB directory value box was set to: "C:\TC\LIB" (without quotes).
Steps to resolve:
Press ALT + C.
Set your current directory as C:\TC\BGI
Press ALT + O + D, and put ../INCLUDE and ../LIB in Include/Lib directory values.
and now... when you'll run your progress, you'll say thanks to me. I like the archduchess C fractal graphics that I'm running on DOS Turbo C right now. Lol.
Go to OPTIONS tab then select directories option then enter the particular path where your turbo c folder exists.
Enter the path in all the four message boxes and it would start working like it did in my case. I have TurboC3 and all the files were together in one common root folder.
Check your environment include path. The file is not in the locations pointed by that environment variable.
Well, I've been working backshift just spent about 6 hours trying to figure this out.
All of the above information led to this conclusion along with a single line in dos prompt screen, when I exited the editor, go to the dos prompt my C: drive is mounted.
I did a dir search and what I found was: the way in which I had mounted the C drive initially looked like this
mount c: /
and my dir did not list all files on the C drive only files within the turboc++ folder.
From that I had drawn the conclusion that my directories should look like:
c:\include
not
c:\turboc++\tc\include
or
c:\tc\include
The real problem was the nature in which I had mounted the drive.
Hope this helps someone.
b.mac
Since you did not mention which version of Turbo C this method below will cover both v2 and v3.
Click on 'Options', 'Directories', enter the proper location for the Include and Lib directories.
On most systems, you'd have to be trying fairly hard not to find '<stdio.h>', to the point where the first reaction is "is <stdio.h> installed". So, I'd be looking to see if the file exists in a plausible location. If not, then your installation of Turbo C is broken; reinstall. If you can find it, then you will have to establish why the compiler is not searching for it in the right place - what are the compiler options you've specified and where is the compiler searching for its headers (and why isn't it searching where the header is).
Make sure the folder with the standard header files is in the projects path.
I don't know where this is in Turbo C, but I would think there's a way of doing this.
First check whether the folder name is right or wrong since while you copying to one folder from other accidently it takes other folder address eg it take C instead of F So from OPTION>DIRECTORY change the folder name
Just Re install the turbo C++ from your Computer and install again in the Directory C:\TC\ Folder.
Again The Problem exists ,then change the directory from FILE>>CHANGE DIRECTORY to C:\TC\BIN\

Resources