- In order to see if you have the GNU C/C++ compiler installed on your system
- Type/Copy/Paste: gcc --version
- If the command is not found, it is likely that gcc/g++ isn't installed.
- Type/Copy/Paste: gcc --version
- 3Install gcc/g++ on your system, consult your Unix or GNU/Linux distribution documentation for the appropriate installation method. If you are using Microsoft Windows, please see the following installation method used to install MinGW GNU C/C++ compiler for Microsoft Windows How to install MinGW( Minimalist GNU C/C++ Compiler) on Microsoft Windows
- 4First, create a working directory using the following command:
- Type/Copy/Paste: mkdir CCPP
- Type/Copy/Paste: mkdir CCPP
- 5Second, change into the directory
- Type/Copy/Paste: cd CCPP
- Type/Copy/Paste: cd CCPP
- 6Third, use a text editor such as nano, gedit, vi, notepad,(on Microsoft Windows ) for example,
- 7Unix/GNU/Linux Instructions:
- Type/Copy/Paste: nano main.c
- Type/Copy/Paste: gedit main.c
- Type/Copy/Paste: vi main.c
- Type/Copy/Paste: nano main.c
- 8Windows Instructions:
- Type/Copy/Paste: notepad main.c
- You can use notepad as a text editor on Microsoft Windows
- Type/Copy/Paste: notepad main.c
- 9Enter the following source code below:
- 10Type/Copy/Paste:
- #include
- #include
- int main()
- {
- printf("Hello World\n");
- return(0);
- }
- #include
- 11Once this task is complete save the source code as a text file in your editor asmain.c
- 12Fourth, compile the file by issuing the following command
- Type/Copy/Paste:
- gcc main.c -o HelloWorld
- Type/Copy/Paste:
- 13Fifth, run the command by issuing the following command
- 14Unix/GNU/Linux instructions:
- Type/Copy/Paste: ./HelloWorld
- Type/Copy/Paste: ./HelloWorld
- 15Microsoft Windows Instructions:
- Type/Copy/Paste: HelloWorld.exe
- On Windows when the HelloWorld.c file is compiled it will usually have an .exe extention.
- Type/Copy/Paste: HelloWorld.exe
- 16To compile multiple files:
- Type/Copy/Paste:
- gcc -o outputfile file1.c file2.c file3.c
- Type/Copy/Paste:
- 17To compile with more error checking using the -Wall tag:
- Type/Copy/Paste:
- gcc -Wall -o outputfile file1.c
- Type/Copy/Paste:
- 18To compile files without linking them:
- Type/Copy/Paste:
- gcc -c file1.c file2.c file3.c
- After the last step, if you want to link them, type: gcc -o outputfile file1.o file2.o file3.o
Thanks to:
No comments:
Post a Comment