You can easily do it with gcc.
compile
$ gcc hoge.c -o hoge
Probably, the file name after compilation is the original file.c without the extension .c.
The format has already been decided. It is possible to change the file name at all, but even if you change the file name after compilation, it is only difficult to understand, and you do not bother to do that.
Then, isn't it annoying to write gcc hoge.c -o hoge
?
So, let's compile with one command.
If you don't have a command, you can make it.
To mess with it, create a shell script under ~ / .bash_profile
in your home directory or /etc/profile.d
.
I think this depends on whether you use it as one user of the server or make it available to all users.
If you want to use it as one user, add the following to ~ / .bash_profile
.
To make it available to all users, create a suitable compile.sh
under /etc/profile.d
and enter the following there.
compile(){
out=`echo $1 | awk -F '.' '{print $1}'`
gcc $1 -o ${out}
}
I will explain it for the time being.
$ 1
is an argument. It's the original C file.
Multiply it by ʻawk. The delimiter recognition is set to
. (Dot), and the first field is extracted. If the file name is
hoge.c, the first field will be
hogeand the second will be
c. Put the extracted
hoge in the variable ʻout
.
After that, the gcc
command outputs the original argument hoge.c
with the hoge
extracted earlier.
After entering, please execute the following.
$ source /etc/profile
Now you can use your own command named compile
.
$ com ←[Tab]Press the key twice
combinedeltarpm command compile complete-ant-cmd.pl
comm compgen complete compopt
You can see that compile
appears as a candidate.
All you have to do now is compile.
$ ls
test.c
$ compile test.c
$ ls
test test.c
Only this. By the way, I'm not familiar with the gcc command. Please let me know if there is something like "Can you do it with gcc alone?" Or "Is there a command like this?"
Recommended Posts