Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the GCC compilation commands

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article gives you an introduction to GCC compilation commands, the content is very detailed, interested friends can refer to reference, I hope to help you.

When you don't have IDE, you may not be used to it at first, but stick to it for a while, you will fall in love with the text editor + compiler mode, whether it is compilation speed or compilation time interface, this way is cooler than IDE, after all, it is free anyway, right? Here to talk about the terminal, probably the vast majority of students have only used Windows under the "CMD", that is,"command prompt", I have heard it called DOS interface and so on. And in Linux there's something that looks similar, called a terminal, or console, etc. As shown in Figure 1.

Figure 1 Command Prompt for Windows and Terminal for Linux

The two pictures in Figure 1 are black and autumn interface. Are the two things different? In fact, these two are completely different things from the perspective of design philosophy. Let's start with the terminal. This terminal is a product inherited by Linux from the Unix era. Now, when it comes to computers, everyone's first reaction is that it should be something like a laptop or desktop. It's very small and everyone has one in the office. In fact, the early computers were too expensive to generate and too large in size. They all existed in the form of minicomputers or mainframes. Maybe each company only had one. Other users used serial ports to plug into this mainframe to work. There was only one called "terminal" in front of them.(or console devices, running programs called shells) files or other office, so Unix's earliest design philosophy was a centralized data processing multiuser multitasking operating system, and Linux inherited this perfectly. Isn't this a bit like today's server architecture? This is why Windows dominates Linux in all other areas, namely the server area, which has always been in Linux's mouth. Later, due to the introduction of GUI in Linux operating system, and these GUI are only a process in Linux system, the real Linux is still that terminal. as shown in figure 2.

Figure 2 Historical "Terminals"

Windows was different. When Windows was born, the personal computer business had already begun to flourish. The DOS system they first developed for IBM PC was called MS-DOS. There were many versions of DOS at that time. Microsoft DOS was just one of them. DOS was a single-user, single-task operating system designed only for users to manipulate data and software on disks. Later, Microsoft really led the operating system coquettish, is its launch of Windows, in fact, Windows interface and the earliest DOS inside a program only, used Windows 95 to know, open the computer presented to you is a command line, to enter a long string of commands to enter the operating system, this mechanism until Windows XP was cancelled, Windows became the real Windows. Naturally, due to certain user habits "DOS interface" came down. The difference between DOS and Shell is roughly as follows. 1, shell case-sensitive, DOS case-insensitive;2, in general, shell command switches can be abbreviated (For example,"-a -l" can be abbreviated as "-al"), while DOS is not allowed;3, the syntax of scripting is very different, for example, the syntax of flow control statements is different, and the syntax of variables is different;4, Shell can be used under UNIX, GNU/Linux and Win.(cygwin bash shell) works, DOS has not heard of working in systems other than Win/DOS;5, shell natively supports regular expressions, DOS does not. Later, after Windows 7, Microsoft also added a software called "Power Shell" to the personal operating system, and the terminal software that came with VS Code before us was Powershell. That's the Shell and command prompt. Shell command In operation, the format of the input command is: command parameter 1 parameter 2 …parameter n. Take a look at the previously used compilation command "gcc -o hello helloeorld.c" as shown in Figure 3. Note that GCC must be case sensitive when running in shell.

Figure 3 GCC Common Options

GCC has a lot of parameter functions, let's look at a few together. As shown in Figure 4, this table only lists a few commonly used parameters. If there are other new parameters that need to be used, we will talk about it in due course. Note that parameter 1 in Figure 3 is what I call "option" later in the article. These two are the same thing. Using helloworld.c as an example, we mentioned earlier that the compilation of a program is divided into four steps: "preprocessing"->"compiling"->"assembling"->"linking". Next, we use gcc to look at the intermediate files they produce step by step. (1) only activate the pretreatment, do not carry out the following three steps, the command used at this time should be "gcc -E ./ helloworld.c > propress.c", this function needs to store the preprocessed file into a new file, we use the name"propress.c"here. as shown in figure 4.

Figure 4 gcc preprocessing command

(2) Compile only, no subsequent steps. The command to use should be "gcc -S .\ helloworld.c", after running, the compiler will output a file named helloworld.s in the current folder, which is the assembly language generated by GCC. as shown in figure 5.

Figure 5. gcc generates assembly language files (3) only generates object files without subsequent linking steps. The command to use should be "gcc -c .\ helloworld.c", after running, the compiler will output a file named helloworld.o in the current folder, which is the target file generated by GCC. as shown in figure 6. VS Code may not be able to open binary files at first, you need to go to the application market to download a plugin called "binary"

Figure 6 Object file

(4) The last step is to use gcc to generate the final executable file. Using the command "gcc -o helloworld helloworld.c" will eventually generate the executable file helloworld.exe. Note that the suffix name of.exe at this time is automatically added and can be hidden. In addition, if you still feel uncomfortable with terminal operation, there is a software called Dev Cpp that is also an IDE integrated with MinGW. You can try it yourself. What about GCC compilation commands to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report