Next: Compiling A Multi-Source C
Up: Compiling A C Program
Previous: Compiling A C Program
Contents
- Once we created the program, we wish to run it. This is usually done by simply typing its name, as in:
$code1
However, this requires that the current directory be in our PATH (which is a variable telling our Unix shell where to look for programs we're trying to run).
- In many cases, this directory is not placed in our PATH. Then lets show this computer who is smarter, and thus we try:
$./code1
This time we explicitly told our Unix shell that we want to run the program from the current directory. If we're lucky enough, this will suffice.
- However, yet one more obstacle could block our path - file permission flags.
- When a file is created in the system, it is immediately given some access permission flags.
- These flags tell the system who should be given access to the file, and what kind of access will be given to them. Now, when the compiler created the program file for us, we became owners of the file.
- Normally, the compiler would make sure that we get all permissions to the file - read, write and execute. It might be, thought that something went wrong, and the permissions are set differently.
In that case, we can set the permissions of the file properly (the owner of a file can normally change the permission flags of the file), using a command like this:
$chmod u+rwx code1
This means the user ('u') should be given ('+') permissions read ('r'), write ('w') and execute ('x') to the file 'code1'. Now we'll surely be able to run our program.
- Note that you cannot just move the file to a different computer an expect it to run;
- it has to be a computer with a matching operating system (to understand the executable file format),
- and matching CPU architecture (to understand the machine-language code that the executable file contains).
- Finally, the run-time environment has to match. For example, if we compiled the program on an operating system with one version of the standard C library, and we try to run it on a version with an incompatible standard C library, the program might crush, or complain that it cannot find the relevant C library. This is especially true for systems that evolve quickly (e.g. Linux with libc5 vs. Linux with libc6).
Next: Compiling A Multi-Source C
Up: Compiling A C Program
Previous: Compiling A C Program
Contents
Cem Ozdogan
2009-05-11