Robert G. Plantz
Setting up a linux development environment for the x86-64 book
- I used Ubuntu for both for writing the book and for program development. The following packages should be installed on Ubuntu 14.04 LTS to create a complete program development environment for using the book:
- g++ — C++ compiler
- gcc-multilab — 32-bit support for C
- binutils-doc —
- gcc-doc —
- g++-multilab — 32-bit support for C++
- Please note that linux distributions differ and constantly change, so you will quite probably need to install a different set of packages if you are not using Ubuntu 14.04 LTS.
To help you to ensure that your development environment is sufficient for using the book, you can download four programs to test it.
These should work on any linux installation.
- Expand the file using the command:
tar –zxvf test_dev_tools.tgzThis will create the folder,
test_dev_tools, with four folders in it,
- Each of these four folders contains the source code for a program, together with a
Makefileto create the program. From inside the program’s folder, use the command:
makewhich should create the respective program.
- If you get any error messages, I recommend contacting someone who is familiar with your particular linux distribution for help. Provide that person with a link to this page, and he or she can probably figure out what needs to be done.
- Expand the file using the command:
- You should also check that the
infodocumentation is installed with the commands:
info as info ld info gcc info g++
Linux Virtual Machine
- A reader, Auroprem Kandaswami, has set up a virtual machine under Windows 7 and installed Debian for use with the book. He has very kindly allowed me to share his procedure here.
- If you have set up some other virtual machine environment to use with the book and wish to share your experience with other readers, please email your comments to me, and I will share them here.
- Here are handy reference sheets.
Do not copy and paste code. We all copy code, and we all like to see our programs work. Copy and paste is the fastest way to do that. But if you type in the program, even if you are copying it, you are forced to read every single character. This is the fastest way to learn the programming language. As you know, getting a single character wrong can mean the difference between a working and non-working program.
Do the exercises at the end of each chapter. If you get stuck, the answers are provided in Appendix E. Take a quick look at my solution to get a couple of hints, then return to working on the solution for yourself.
Read the error messages. When you make a mistake (yes, you will make them; so do I), the compiler and assembler programs provide error messages that usually give you a good clue about what your mistake is. For example, without having all the source code, can you tell me what my mistake is from this error message?
bob@bob-laptop:~/programing$ gcc -Wall copy_loop.c
copy_loop.c: In function 'main':
copy_loop.c:12: error: expected ',' or ';' before 'while'
copy_loop.c:10: warning: unused variable 'temp2'
copy_loop.c:9: warning: unused variable 'temp1'
You should be able to quickly spot the error in my C source code:
char *temp1 = p1;
char *temp2 = p2
If you have a bug in your program, explain your code to somebody else. Ask another programmer to help you find the bug. Go through it line by line, explaining the purpose of each line. Most of the time you will spot your error before the other person does.
Using the Book With Other Operating Systems
- I have verified that the programs in the book will run on OpenSolaris 2009.06 installed on an x86-64 system with the following changes:
gcc. The default is 32-bit.
as. The default is 32-bit.
The system call codes (
eaxregister in Table 8.3 on page 185) are:
exit = 1,
read = 3, and
write = 4.
When writing a stand-alone assembly language program (Section 8.7, page 185) use the
-melf-x86-64option for 64-bit.
- I believe they will also run under other Unix operating systems — Mac OS X, *BSD, etc. — with minor changes in the command line options.