Why gcc a out




















This way, you might find the information here useful, even if the system you're using does not have the GNU tools installed. In this lovely tutorial, we'll deal with compilation of a C program, using the compiler directly from the command line. It might be that you'll eventually use a more sophisticated interface an IDE - Integrated Development Environment of some sort, but the common denominator you'll always find is the plain command line interface.

Further more, even if you use an IDE, it could help you understand how things work "behind the scenes". We'll see how to compile a program, how to combine several source files into a single program, how to add debug information and how to optimize code.

The easiest case of compilation is when you have all your source code set in a single file. This removes any unnecessary steps of synchronizing several files or thinking too much. If you're using a GNU compiler, you'll write 'gcc' instead. If you're using a Solaris system, you might use 'acc', and so on. Every compiler might show its messages errors, warnings, etc. Note that some older systems e. You might complain that 'a.

Once we created the program, we wish to run it. In many cases, this directory is not placed in our PATH. Then lets show this computer who is smarter, and thus we try:. 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.

Traditional Unix systems use 3 kinds of entities to which they grant or deny access: The user which owns the file, the group which owns the file, and everybody else. Each of these entities may be given access to read the file 'r' , write to the file 'w' and execute the file 'x'. 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. Now we'll surely be able to run our program. Again, normally you'll have no problem running the file, but if you copy it to a different directory, or transfer it to a different computer over the network, it might loose its original permissions, and thus you'll need to set them properly, as shown above.

Note too 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. Linux with libc5 vs. Linux with libc6 , so beware. Normally, when we write a program, we want to be able to debug it - that is, test it using a debugger that allows running it step by step, setting a break point before a given command is executed, looking at contents of variables during program execution, and so on.

In order for the debugger to be able to relate between the executable program and the original source code, we need to tell the compiler to insert information to the resulting executable program that'll help the debugger.

This information is called "debug information". You will note that the resulting file is much larger then that created without usage of the '-g' flag. The difference in size is due to the debug information. We will use this standard in cs We will also use the -g flag, which allows us to use the debugger, gdb to give us exact line numbers in our code when we run it.

Toggle navigation CS Spring archived. See the man page for gcc for more details or see here , but here are the basics: -O or -O1 : Optimize.

Optimizing compilation takes somewhat more time, and a lot more memory for a large function. With -O, the compiler tries to reduce code size and execution time, without performing any optimizations that take a great deal of compilation time. GCC performs nearly all supported optimizations that do not involve a space-speed tradeoff.

As compared to -O, this option increases both compilation time and the performance of the generated code. This is often the best option to use. Learn more. What is this a. Ask Question. Asked 4 years, 9 months ago. Active 1 year, 2 months ago. Viewed 17k times. You can change it with the appropriate command-line option for your C compiler.

As for why it's disappearing, we can only guess which is bad, and makes your question off-topic btw , but I've had cases where an overprotective antivirus would do that. This a. No mistery there. Add a comment. Active Oldest Votes. If you want gcc to generate an executable with specific name, use the -o switch followed with the desired name: gcc hello.

Eugene Sh. Might be a good idea to mention that the proper usage is gcc -o hello hello. Will do — Eugene Sh. Maybe add that gcc a. Yatin The explanation is following this remark, but added the same into it, check it out.



0コメント

  • 1000 / 1000