Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcc and g++ command prompt compiling and linking

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.

like image 677
silent Avatar asked Sep 16 '09 11:09

silent


People also ask

Is GCC A compiler and linker?

The GNU Compiler Collection (gcc)The GNU Compiler Collection, gcc, can compile programs written in C, C++, Java and several other languages. It provides many useful command line options and syntax extensions, and also serves as a powerful frontend for the GNU linker, ld.

Should I compile with GCC or G ++?

Both are the compilers in Linux to compile and run C and C++ programs. Initially gcc was the GNU C Compiler but now a day's GCC (GNU Compiler Collections) provides many compilers, two are: gcc and g++. gcc is used to compile C program while g++ is used to compile C++ program.

Is G ++ and GCC the same?

DIFFERENCE BETWEEN g++ & gccg++ is used to compile C++ program. gcc is used to compile C program.

What is GCC in compiling?

The GNU Compiler Collection, commonly known as GCC, is a set of compilers and development tools available for Linux, Windows, various BSDs, and a wide assortment of other operating systems. It includes support primarily for C and C++ and includes Objective-C, Ada, Go, Fortran, and D.


2 Answers

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.

like image 190
avd Avatar answered Nov 03 '22 01:11

avd


Add this c:\program files\gcc\bin to PATH environment variable. And then you can execute gcc/g++ from any directory

like image 45
vpram86 Avatar answered Nov 03 '22 01:11

vpram86