GCC
| Introduction | |
| Before installation | |
| Installation | |
| Linux subsystem for Windows | |
| Installation Cygwin |
Introduction
Before installation
Check if gcc can be installed in the cmd command
gcc --version
If gcc is installed, you will see a version.
If gcc is not installed, you will see the following message.
Microsoft Windows [Version 10.0.18363.720] (c) 2019 Microsoft Corporation. All rights reserved. C:\Users\Andrei>gcc --version 'gcc' is not recognized as an internal or external command, operable program or batch file.
Installation
To work in Windows You need MinGW to download it on the website.
nuwen.net/mingw.html
I download mingw-17.1.exe
Follow the instructions.
Double Click on Mingw-17.1.exe
After installation, add C:\MinGW\bin to the PATH system variable.
If you don’t know how to do it, read my article.
«System variable PATH»
Now the gcc-version command must return the compiler version.
gcc --version
Microsoft Windows [Version 10.0.18363.720] (c) 2019 Microsoft Corporation. All rights reserved. C:\Users\Andrei>gcc --version gcc (GCC) 9.2.0 Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
If this does not happen, restart the console. If it doesn't work, reset. Windows.
After installation
So, you installed MinGW written the simplest program 3.cpp, compile using gcc.
gcc 3.cpp
And in return
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Andrei\AppData\Local\Temp\ccuoNssB.o:3.cpp:(.text+0x28): undefined reference to `std::ios_base::Init::~Init()' c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Andrei\AppData\Local\Temp\ccuoNssB.o:3.cpp:(.text+0x58): undefined reference to `std::ios_base::Init::Init()' collect2.exe: error: ld returned 1 exit status
My advice is to try g+&plus.
g++ 3.cpp
If you plan to write software that will work under
Unix-like operating systems, for example
Linux
or
OpenBSD
There is no need to install MinGW.
Try adding a subsystem to your Windows Linux and install the gcc there.
Installation gcc in Linux subsystem for Windows
sudo apt-update
sudo apt install build-essentials
gcc -v
Installation Cygwin
If for some reason you do not fit the above options - install cygwin
cygwin.com
I have only had a negative experience with it so far, but you can do better.
ISOCPP isocpp.org
Options
-o is an option for compiler
| Option Flag | Function |
|---|---|
| -o filename | Names the output file |
| -S | Directs the compiler to produce an assembly source file but not to assemble the program. |
-c
Directs the compiler to suppress linking with ld(1) and to produce a .o file for each source file
Compile or assemble the source files, but do not link. The linking stage simply is not done. The ultimate output is in the form of an object file for each source file. By default, the object file name for a source file is made by replacing the suffix .c, .i, .s, etc., with .o. Unrecognized input files, not requiring compilation or assembly, are ignored.
cc -c Meaning
cc stands for C compiler
There are multiple commonly availabe C compilers
In this article
gcc
was used
-c is an option mentioned
here
Article author: Andrei Olegovich
| C development | |
| Textbook on C | |
| Boolean in C | |
| Sockets in C | |
| K&R | |
| What is argc, char * argv[] | |
| Function scanf() | |
| Pointers | |
| Structures in C | |
| Operator «arrow» pointer to member structure |