gcc and g++ command prompt compiling and linking
-
07-07-2019 - |
Question
Hey there, I have a small problem with compiling and linking with the command prompt(windows xp). Every .c file and .cpp file I compile or link has to be in the same directory as gcc (C:\Program Files\gcc\bin) and its quite hard to keep track of my files among all those gcc related files and its annoying too:). My question is how do I compile a file in a desktop folder using the command prompt?
usually I go:
c:\program files\gcc\bin> gcc -c test.c test2.c
when my source files are in bin.
What command do I use to compile When a file is situated elsewhere.
Solution
Right Click My COmputer. GO to properties. Go to advanced tab. There is a button below Environment Variables. Find "PATH" in the global environment variables. Add
c:\program files\gcc\bin
after appending the semicolon at the end of previous entry.
OTHER TIPS
Add this c:\program files\gcc\bin
to PATH environment variable.
And then you can execute gcc/g++ from any directory
sounds like you dont have gcc in your PATH environment variable. Either add c:c:\program files\gcc\bin to this variable or call it with the absolute path name from whatever source directory your files are in