Проверить, установлен ли gcc можно в cmd командой
gcc --version
Если gcc установлени, Вы увидите версию
Если gcc не установлен, Вы увидите следующее сообщение
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.
Для работы в Windows нужен MinGW скачать его можно на сайте
nuwen.net/mingw.html
Я скачиваю mingw-17.1.exe
Далее действую по инструкции
Двойной клик на mingw-17.1.exe
После установки нужно добавить C:\MinGW\bin в системную переменную среды PATH.
Если Вы не знаете как это сделать, прочитайте мою статью
«Системная переменная PATH»
Теперь команда gcc --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.
Если этого не происходит - перезапустите консоль. Если не помогло - перезапустите Windows.
Итак, Вы установили MinGW написали простейшую программу 3.cpp, компилируете с помощью gcc
gcc 3.cpp
А в ответ
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
Мой совет - попробуйте g++
g++ 3.cpp
Если Вы планируете писать софт, который должен будет работать под
UNIX-подобными ОС, например
Linux
или
OpenBSD
то устанавливать MinGW не стоит.
Попробуйте добавить в Ваш Windows подсистему для Linux и установить gcc там.
sudo apt-update
sudo apt install build-essentials
gcc -v
Если по каким-то причинам Вам не подходят перечисленные выше варианты - установите cygwin
cygwin.com
У меня пока что только негативный опыт работы с ним, но у Вас может получиться лучше.
ISOCPP isocpp.org
-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. |
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 stands for C compiler
There are multiple commonly availabe C compilers
In this article
gcc
was used
-c is an option mentioned
here
|
Share in social media:
|