Installing GNAT in Linux and Unix
Total Page:16
File Type:pdf, Size:1020Kb
APPENDIX A Installing GNAT in Linux and Unix When it comes to installing the Ada compiler on a Linux (or Unix) machine, first check to see if you can install it via your package manager. Do the following in the command line; you might need root privileges: 1) Debian/Ubuntu/LinuxMint: $ sudo apt install gnat $ sudo apt install gprbuild 2) Gentoo: $ emerge dev-lang/gnat 3) Fedora/CentOS: $ yum install fedora-gnat-project-common gprbuild 4) For FreeBSD, do the following in the command line (you might need root privileges): $ pkg install gps-ide Once the install finishes successfully, open a terminal with non-privileged user permissions and run the “gnatmake –version” command, like so: > gnatmake --version GNATMAKE 6.2.1 20160830 Copyright (C) 1995-2016, Free Software Foundation, Inc. 319 © Andrew T. Shvets 2020 A. T. Shvets, Beginning Ada Programming, https://doi.org/10.1007/978-1-4842-5428-8 APPENDIX A INSTaLLING GNAT IN Linux and UNIX This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. And run the gprbuild utility as well: > gprbuild --version GPRBUILD GPL 2016 (20160515) (x86_64-pc-linux-gnu) Copyright (C) 2004-2016, AdaCore 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 you see output similar to what is shown, then you are finished and can go on with the rest of the book. If you do not see the version of either gnatmake or gprbuild, check to make sure that your install was successful. Connectivity issues as well as installation conflicts can stop this process. However, if you did all of the above and still do not see the version of the utility printed out (or your OS does not have the above package to install), then do the following: 1) Go to the AdaCore web site from where you will get the correct binaries: www.adacore.com/community 2) Click the picture with the words “GNAT Community Download.” 3) Locate the link that is just below the title “GNAT GPL Ada,” click it, and download the executable. The link will look similar to this: gnat-gpl-2017-x86_64-linux-bin.tar.gz. 4) Create an install location. In our case it will be located in the home directory: $ mkdir ~/ada_install 5) After the download is complete, move the file to a location where you can open it up, if you have not done this already; you can create a temporary directory where the download is residing. 320 APPENDIX A INSTaLLING GNAT IN Linux and UNIX 6) In that directory run the binary that you downloaded: $ ./gnat-community-2019-20190517-x86_64-linux-bin Now follow these steps to complete the install: a) When you run the script, on the first printout of text, simply press Enter. b) On the second printout, specify the directory where you want to have your Ada compiler installed. If the directory is not created, then go create one now. Once this directory is made, enter the direct path to it, meaning DO NOT type this: ~/ada_install But type this: /home/adadeveloper/ada_compiler Take care to enter the path correctly, since there is no auto- complete for filenames when you hit the Tab key. c) Hit the Enter key when ready to proceed. d) On the next text printout, you will be asked if you want to proceed with the install; enter “Y” and hit the Enter key. If prompted again to verify that you are certain that you want to proceed, enter “Y” and hit the Enter key again. The install can take some time to complete; feel free to grab more tea or coffee. e) In your ~/.bashrc file (or whichever configuration file corresponds to the shell that you use), insert the following text at the bottom: $PATH=/home/adadeveloper/ada_compiler:$PATH; export $PATH In a new terminal, reload the file in question: $ source ~/.bashrc 321 APPENDIX A INSTaLLING GNAT IN Linux and UNIX f) Once the install finishes successfully, open a non-privileged terminal and run the “gnatmake –version” command: > gnatmake --version GNATMAKE 6.2.1 20160830 Copyright (C) 1995-2016, 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. You should see output similar to what is displayed above. And run the gprbuild utility as well: > gprbuild --version GPRBUILD GPL 2016 (20160515) (x86_64-pc-linux-gnu) Copyright (C) 2004-2016, AdaCore This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. You should see similar output. 7) gprbuild is necessary for Chapters 16 and 17. The lack of this toolset will not hinder you for the preceding chapters. 322 APPENDIX B Installing GNAT in Windows To install on Windows, follow these steps: 1) Go to the AdaCore web site where you will get the correct binaries: www.adacore.com/community 2) Click the picture with the words “GNAT Community Download.” 3) Locate the link that is just below the title “GNAT GPL Ada,” click it, and download the executable. The link will look similar to this: gnat-gpl-2017-x86-windows-bin.exe. 4) When prompted, save the executable at the place of your choosing. 5) In Windows Explorer, navigate to the location where the download is saved. 6) Double-click the file to begin the install. 7) In the window “GNAT GPL 2017,” click “Next”. 8) Click “Next” in order to accept the default destination folder. 9) Click “Next” in order to accept the default Menu Folder location. 10) Click “Install” in order to start the install. This might take some time to finish. 11) Click “Finish” when the install is done. 323 © Andrew T. Shvets 2020 A. T. Shvets, Beginning Ada Programming, https://doi.org/10.1007/978-1-4842-5428-8 APPENDIX B INSTaLLING GNAT in WindowS 12) Now, it is time to run a test. Open the command prompt. How you get to it depends on the version of Windows that you are running. If you do not know how to open this window, please consult Microsoft’s web site or search for it online. 13) Now execute the “gnatmake --version” command, and you should see the following: C:\Users\ada>gnatmake --version GNATMAKE GPL 2017 (20170515-49) Copyright (C) 1995-2017, 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 you do not see the preceding data, please re-trace the install procedure and ensure that all steps were executed successfully. 14) Also, do the same for the gprbuild utility and you should see the following: C:\Users\ada>gprbuild --version GPRBUILD GPL 2017 (20170515) (i686-pc-mingw32) Copyright (C) 2004-2017, AdaCore 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 you do not see the output, please re-trace the install procedure and ensure that all steps were executed successfully. gprbuild is necessary for Chapters 16 and 17. The lack of this toolset will not hinder you for the preceding chapters. 324 APPENDIX C Reserved Keywords Here is a list of words that you cannot use as a name for a package, procedure, function, or variable. These words are reserved by the compiler for its own purposes. Avoid them standalone, but feel free to use them as parts of variables, packages, and so on. abort else null select abs elsif of separate abstract end or some accept entry others subtype access exception out synchronized aliased exit overriding tagged all for package task and function pragma terminate array generic private then at goto∗ procedure type begin if protected until body in raise use case interface range when constant is record while declare limited rem with delay loop renames xor (continued) 325 © Andrew T. Shvets 2020 A. T. Shvets, Beginning Ada Programming, https://doi.org/10.1007/978-1-4842-5428-8 APPENDIX C RESErVED KEYWOrDS delta mod requeue digits new return do not reverse ∗The only “bad” keyword that is in the entire bunch. It is here because of legacy code reasons. It’s easy to start using this keyword and it easily creates some very confusing spaghetti code. Also, when you do use them as part of other names, do so where they stand out from the original keywords. This would be a poor example of a name using a keyword: arrayb However, this is a much better way of doing things: InventoryArray 326 APPENDIX D Debugging Ada Applications Many problems that you encounter in your software development adventures will be easy to figure out by simply printing out the variable name in the command line. This way, it will be immediately obvious if something is wrong and why. However, this is not always the case, and for those particular issues, a debugger is a must. The goal of this appendix is to walk you through a very simple program and view its execution in a debugger. When you are finished, you will be equipped with basic knowledge of how to use the gdb debugger and how to delve inside of your applications. All of the following commands that are shown can be executed in Windows (in a command prompt) and in a Linux or Unix operating system.