- C language
- Compile
- here
Procedure for executing C language source code
I will explain the procedure to execute the C language source code. Compile ・ Links ・ execution, but let's first aim to execute it. It is assumed that C language development environment has been built.
Compile and link to generate an executable file
To compile and link and generate an executable file, use the "-o" option with the gcc command.
Specify the output file name with the "-o" option.
gcc -o output file name input file name
This command will compile and link all at once. Since there is only one input file, I don't feel like linking. I haven't explained the meaning of the word link yet. Let's try as far as we can.
Let's create an executable file called "test" from a C language source file called "test.c".
// test.c #include <stdio.h> int main (void) { printf("Hello World! \ N"); }
Generate an executable file with the gcc command.
gcc -o test test.c
Execute the executable file
Let's execute the created executable file. An executable file is a general program.
# Execute the executable file (program) ./test
This is the output result.
Hello World!
Notice the "./" at the beginning. In Unix / Linux, just writing "test" to reduce security risk will prevent the executable file from being executed. It has become. Remember that you need to add "./" when executing an executable file in the current directory. If it's an absolute path, you don't have to be aware of this.
You can also write compile, link, and execute in one line.
gcc -o test test.c && ./test