guide:D9b6fc95f3: Difference between revisions

From Stochiki
No edit summary
 
mNo edit summary
Line 1: Line 1:
==Dev-C++==


[[wikipedia:Dev-C Plus Plus|Dev C++]] is an Integrated Development Environment (IDE) for the C++ programming language, available from [http://www.bloodshed.net/ Bloodshed Software]. An updated version is available at [http://orwelldevcpp.blogspot.com/ Orwell Dev-C++].<br />
C++ is a programming language which contains within itself most of the C language, plus extensions. Most C++ compilers will compile C programs, sometimes with a few adjustments (like invoking them with a different name or command line switch). Therefore, you can use Dev C++ for C development.
However, Dev C++ is not the compiler. It is designed to use the [[wikipedia:MinGW|MinGW]] or [[wikipedia:Cygwin|Cygwin]] versions of [[Wikipedia:GCC|GCC]] - both of which can be obtained as part of the Dev C++ package, although they are completely different projects. <br />
Dev C++ simply provides an editor, syntax highlighting, some facilities for the visualisation of code (like class and package browsing) and a graphical interface to the chosen compiler. Because Dev C++ analyses the error messages produced by the compiler and attempts to distinguish the line numbers from the errors themselves, the use of other compiler software is discouraged since the format of their error messages is likely to be different.
The latest version of Dev-C++ is a [[Wikipedia:beta version|beta]] for version 5. However, it still has a significant number of bugs. All the features are there, and it is quite usable. It is considered one of the best free software C IDEs available for Windows.
A version of Dev C++ for Linux is in the pipeline. It is not quite usable yet, however. Linux users already have a wealth of IDEs available. (e.g. [[wikipedia:KDevelop|KDevelop]] and [[wikipedia:Anjuta|Anjuta]].) Most of the graphical text editors, and other common editors such as ''emacs'' and ''vim'', support [[wikipedia:syntax highlighting|syntax highlighting]].
===Windows===
# Go to https://sourceforge.net/projects/orwelldevcpp/ and pick the download option.
# The setup is pretty straight forward. Make sure the compiler option is ticked.
# You can now use the environment provided by the software to write and run your code.
# OPTIONALLY: "C:\Program Files (x86)\Dev-Cpp\MinGW64\bin" can be added to the global PATH variable of the operating system to compile with GCC from a command prompt.
==GCC==
The [[wikipedia:GNU Compiler Collection|GNU Compiler Collection]] (GCC) is a [[wikipedia:free software|free/libre]] set of compilers developed by the [[wikipedia:Free Software Foundation|Free Software Foundation]] and can be installed on a wide variety of operating systems. GCC commands are used throughout this book to demonstrate how to compile C code so you are encouraged to take the time to install GCC on your machine.
===GNU/Linux===
On '''GNU/Linux,''' Installing the GNU C Compiler can vary in method from [[wikipedia:Linux distribution|distribution]] to distribution. (Type in '''cc -v''' to see if it is installed already.)
* For [[wikipedia:Ubuntu|Ubuntu]], install the GCC compiler (along with other necessary tools) by running <code>sudo [[wikipedia:Advanced Packaging Tool|apt]] install build-essential</code> in the terminal.
* For [[wikipedia:Debian|Debian]], install the GCC compiler (as root) by running <code>[[wikipedia:Advanced Packaging Tool|apt]] install gcc</code> in the terminal.
* For [[wikipedia:Fedora_(operating_system)|Fedora]], install the GCC compiler (as root) by running <code>[[wikipedia:DNF_(software)|dnf]] install gcc</code> in the terminal.
* For [[wikipedia:Red_Hat_Enterprise_Linux|RHEL]], install the GCC compiler (as root) by running <code>[[wikipedia:DNF_(software)|dnf]] install gcc</code> in the terminal.
* For [[wikipedia:Mandrake|Mandrake]], install the GCC compiler (as root) by running <code>[[wikipedia:urpmi|urpmi]] gcc</code> in the terminal.
* For [[wikipedia:Slackware|Slackware]], the package is available on their [http://www.slackware.com/pb/ website] - simply download, and type <code>installpkg gcc-xxxxx.tgz</code> in the terminal.
* For [[wikipedia:Gentoo|Gentoo]], you should already have GCC installed as it will have been used when you first installed.  To update it run (as root) <code>emerge -uav gcc</code> in the terminal.
* For [[wikipedia:Arch Linux|Arch Linux]], install the GCC compiler (as root) by running <code>pacman -S gcc</code> in the terminal.
* For [[wikipedia: Void Linux| Void Linux]], install the GCC compiler (as root) by running <code>xbps-install -S gcc</code> in the terminal.
* If you cannot become root, get the GCC tarball from ftp://ftp.gnu.org/ and follow the instructions in it to compile and install in your home directory. Be warned though, you need a C compiler to do that - yes, GCC itself is written in C.
* You can use a commercial C compiler/IDE.
===macOS===
The simplest method for obtaining a compiler is to install Apple's proprietary IDE, Xcode, [https://apps.apple.com/us/app/xcode/id497799835?mt=12 available for free.]
Xcode comes bundled with a GCC-compatible compiler called [https://clang.llvm.org clang] which replaced GCC as Xcode's default C compiler a number of years ago. But because Xcode aliases the <code>gcc</code> command to the clang compiler, GCC installation isn't necessary to compile the example code in this book.
If you prefer using the GCC compiler, the third-party package manager, [https://brew.sh Homebrew,] provides an easy installation process. You'll first need to [https://docs.brew.sh/Installation install Homebrew], and then issue the <code>brew install</code> command to install the desired [https://formulae.brew.sh/formula/gcc GCC Homebrew formulae.] You may want to find a recent tutorial that will step you through this process as other commands may be necessary to get GCC set up flawlessly on your system, especially if you already have Xcode installed.
For hardcore computer enthusiasts, GCC can be compiled directly from the source code. We highly recommend searching out and following an up-to-date tutorial for installing GCC from source files.
===BSD Family Systems===
* For [[wikipedia:FreeBSD|FreeBSD]], [[wikipedia:NetBSD|NetBSD]], [[wikipedia:OpenBSD|OpenBSD]], [[wikipedia:DragonFly BSD|DragonFly BSD]] the port of GNU GCC is available in the base system, or it could be obtained using the ports collection or [[wikipedia:pkgsrc|pkgsrc]].
===Windows===
There are three ways to use GCC on Windows: Cygwin, MinGW and Windows Subsystem for Linux (WSL). Applications compiled with Cygwin will not run on any computer without Cygwin, so MinGW is recommended. MinGW is simpler to install, and takes less disk space.
====MinGW====
# Go to http://sourceforge.net/projects/mingw/ download and save this to your hard drive.
# Once the download is finished, open it and follow the instructions. You can also choose to install additional compilers, or the tool Make, but these aren't necessary.
# Now you need to set your PATH. Right-click on "My computer" and click "Properties". Go to the "Advanced" tab and click on "Environment variables". Go to the "System variables" section and scroll down until you see "Path". Click on it, then click "edit". Add "C:\MinGW\bin\" (without the quotes) to the end.
# To test if GCC works, open a command prompt and type "gcc". You should get the message "gcc: fatal error: no input files compilation terminated.". If you get this message, GCC is installed correctly.
====Cygwin====
# Go to http://www.cygwin.com and click on the "Install Cygwin Now" button in the upper right corner of the page.
# Click "run" in the window that pops up, and click "next" several times, accepting all the default settings.
# Choose any of the Download sites ("ftp.easynet.be", etc.) when that window comes up; press "next" and the Cygwin installer should start downloading.
# When the "Select Packages" window appears, scroll down to the heading "Devel" and click on the "+" by it. In the list of packages that now displays, scroll down and find the "gcc-core" package; this is the compiler.  Click once on the word "Skip", and it should change to some number like "3.4" etc. (the version number), and an "X" will appear next to "gcc-core" and several other related packages that will now be downloaded.
# Click "next" and the compiler as well as the Cygwin tools should start downloading; this could take a while.  While you're waiting for the installation to finish, download any text-editor designed for programming.  While Cygwin does include some, you may prefer doing a web search to find other alternatives.  While using a stock text editor is possible, it is not ideal.
# Once the Cygwin downloads are finished and you have clicked "next", etc. to finish the installation, double-click the Cygwin icon on your desktop to begin the Cygwin "command prompt".  Your home directory will automatically be set up in the Cygwin folder, which now should be at "C:\cygwin" (the Cygwin folder is in some ways like a small unix/linux computer on your Windows machine -- not technically of course, but it may be helpful to think of it that way).
# Type "gcc" at the Cygwin prompt and press "enter"; if "gcc: no input files" or something like it appears you have succeeded and now have the GCC compiler on your computer (and congratulations -- you have also just received your first error message!).
====Windows Subsystem for Linux====
# Go to http://aka.ms/wsldocs and follow the steps to install [https://docs.microsoft.com/en-us/windows/wsl/install-win10 WSL]
# Go to https://aka.ms/vscode and follow the steps to install [https://code.visualstudio.com/docs/setup/windows VSCode]
# Follow the [https://code.visualstudio.com/docs/languages/cpp#_getting-started guide] and choose [https://code.visualstudio.com/docs/cpp/config-wsl Get Started with C++ and WSL]
# As a result you will need to install possibly [https://code.visualstudio.com/docs/cpp/config-wsl#_set-up-your-linux-environment Ubuntu] and set-up accordingly installing GCC like the Linux guide above.
The current stable (usable) version of GCC is 4.9.1 published on 2014-07-16, which supports several platforms. In fact, GCC is not only a C compiler, but a family of compilers for several languages, such as C++, [[Ada Programming|Ada]], [[Java]], and [[Fortran]].

Revision as of 11:38, 13 May 2024

Dev-C++

Dev C++ is an Integrated Development Environment (IDE) for the C++ programming language, available from Bloodshed Software. An updated version is available at Orwell Dev-C++.
C++ is a programming language which contains within itself most of the C language, plus extensions. Most C++ compilers will compile C programs, sometimes with a few adjustments (like invoking them with a different name or command line switch). Therefore, you can use Dev C++ for C development.

However, Dev C++ is not the compiler. It is designed to use the MinGW or Cygwin versions of GCC - both of which can be obtained as part of the Dev C++ package, although they are completely different projects.
Dev C++ simply provides an editor, syntax highlighting, some facilities for the visualisation of code (like class and package browsing) and a graphical interface to the chosen compiler. Because Dev C++ analyses the error messages produced by the compiler and attempts to distinguish the line numbers from the errors themselves, the use of other compiler software is discouraged since the format of their error messages is likely to be different.

The latest version of Dev-C++ is a beta for version 5. However, it still has a significant number of bugs. All the features are there, and it is quite usable. It is considered one of the best free software C IDEs available for Windows.

A version of Dev C++ for Linux is in the pipeline. It is not quite usable yet, however. Linux users already have a wealth of IDEs available. (e.g. KDevelop and Anjuta.) Most of the graphical text editors, and other common editors such as emacs and vim, support syntax highlighting.

Windows

  1. Go to https://sourceforge.net/projects/orwelldevcpp/ and pick the download option.
  2. The setup is pretty straight forward. Make sure the compiler option is ticked.
  3. You can now use the environment provided by the software to write and run your code.
  4. OPTIONALLY: "C:\Program Files (x86)\Dev-Cpp\MinGW64\bin" can be added to the global PATH variable of the operating system to compile with GCC from a command prompt.

GCC

The GNU Compiler Collection (GCC) is a free/libre set of compilers developed by the Free Software Foundation and can be installed on a wide variety of operating systems. GCC commands are used throughout this book to demonstrate how to compile C code so you are encouraged to take the time to install GCC on your machine.

GNU/Linux

On GNU/Linux, Installing the GNU C Compiler can vary in method from distribution to distribution. (Type in cc -v to see if it is installed already.)

  • For Ubuntu, install the GCC compiler (along with other necessary tools) by running sudo apt install build-essential in the terminal.
  • For Debian, install the GCC compiler (as root) by running apt install gcc in the terminal.
  • For Fedora, install the GCC compiler (as root) by running dnf install gcc in the terminal.
  • For RHEL, install the GCC compiler (as root) by running dnf install gcc in the terminal.
  • For Mandrake, install the GCC compiler (as root) by running urpmi gcc in the terminal.
  • For Slackware, the package is available on their website - simply download, and type installpkg gcc-xxxxx.tgz in the terminal.
  • For Gentoo, you should already have GCC installed as it will have been used when you first installed. To update it run (as root) emerge -uav gcc in the terminal.
  • For Arch Linux, install the GCC compiler (as root) by running pacman -S gcc in the terminal.
  • For Void Linux, install the GCC compiler (as root) by running xbps-install -S gcc in the terminal.
  • If you cannot become root, get the GCC tarball from ftp://ftp.gnu.org/ and follow the instructions in it to compile and install in your home directory. Be warned though, you need a C compiler to do that - yes, GCC itself is written in C.
  • You can use a commercial C compiler/IDE.

macOS

The simplest method for obtaining a compiler is to install Apple's proprietary IDE, Xcode, available for free.

Xcode comes bundled with a GCC-compatible compiler called clang which replaced GCC as Xcode's default C compiler a number of years ago. But because Xcode aliases the gcc command to the clang compiler, GCC installation isn't necessary to compile the example code in this book.

If you prefer using the GCC compiler, the third-party package manager, Homebrew, provides an easy installation process. You'll first need to install Homebrew, and then issue the brew install command to install the desired GCC Homebrew formulae. You may want to find a recent tutorial that will step you through this process as other commands may be necessary to get GCC set up flawlessly on your system, especially if you already have Xcode installed.

For hardcore computer enthusiasts, GCC can be compiled directly from the source code. We highly recommend searching out and following an up-to-date tutorial for installing GCC from source files.

BSD Family Systems

Windows

There are three ways to use GCC on Windows: Cygwin, MinGW and Windows Subsystem for Linux (WSL). Applications compiled with Cygwin will not run on any computer without Cygwin, so MinGW is recommended. MinGW is simpler to install, and takes less disk space.

MinGW

  1. Go to http://sourceforge.net/projects/mingw/ download and save this to your hard drive.
  2. Once the download is finished, open it and follow the instructions. You can also choose to install additional compilers, or the tool Make, but these aren't necessary.
  3. Now you need to set your PATH. Right-click on "My computer" and click "Properties". Go to the "Advanced" tab and click on "Environment variables". Go to the "System variables" section and scroll down until you see "Path". Click on it, then click "edit". Add "C:\MinGW\bin\" (without the quotes) to the end.
  4. To test if GCC works, open a command prompt and type "gcc". You should get the message "gcc: fatal error: no input files compilation terminated.". If you get this message, GCC is installed correctly.

Cygwin

  1. Go to http://www.cygwin.com and click on the "Install Cygwin Now" button in the upper right corner of the page.
  2. Click "run" in the window that pops up, and click "next" several times, accepting all the default settings.
  3. Choose any of the Download sites ("ftp.easynet.be", etc.) when that window comes up; press "next" and the Cygwin installer should start downloading.
  4. When the "Select Packages" window appears, scroll down to the heading "Devel" and click on the "+" by it. In the list of packages that now displays, scroll down and find the "gcc-core" package; this is the compiler. Click once on the word "Skip", and it should change to some number like "3.4" etc. (the version number), and an "X" will appear next to "gcc-core" and several other related packages that will now be downloaded.
  5. Click "next" and the compiler as well as the Cygwin tools should start downloading; this could take a while. While you're waiting for the installation to finish, download any text-editor designed for programming. While Cygwin does include some, you may prefer doing a web search to find other alternatives. While using a stock text editor is possible, it is not ideal.
  6. Once the Cygwin downloads are finished and you have clicked "next", etc. to finish the installation, double-click the Cygwin icon on your desktop to begin the Cygwin "command prompt". Your home directory will automatically be set up in the Cygwin folder, which now should be at "C:\cygwin" (the Cygwin folder is in some ways like a small unix/linux computer on your Windows machine -- not technically of course, but it may be helpful to think of it that way).
  7. Type "gcc" at the Cygwin prompt and press "enter"; if "gcc: no input files" or something like it appears you have succeeded and now have the GCC compiler on your computer (and congratulations -- you have also just received your first error message!).

Windows Subsystem for Linux

  1. Go to http://aka.ms/wsldocs and follow the steps to install WSL
  2. Go to https://aka.ms/vscode and follow the steps to install VSCode
  3. Follow the guide and choose Get Started with C++ and WSL
  4. As a result you will need to install possibly Ubuntu and set-up accordingly installing GCC like the Linux guide above.

The current stable (usable) version of GCC is 4.9.1 published on 2014-07-16, which supports several platforms. In fact, GCC is not only a C compiler, but a family of compilers for several languages, such as C++, Ada, Java, and Fortran.