I am trying to add options to the make
command. For example to add -l option to include libraries. Something like clang filename.c -o filename
to clang filename.c -o filename -l{libary}
What should I do and what file should I edit?
Since you don't have a Makefile, compilation and linking of your program relies on implicit rules built in to make
. In the case of C source code, the implicit rule for Linking a single object file is:
$(CC) $(LDFLAGS) n.o $(LOADLIBES) $(LDLIBS)
So you can add libraries via the LDLIBS
variable e.g.
make LDLIBS='-lfoo'
or
LDLIBS='-lfoo' make
make
command line - exactly as I wrote. Or if you're too lazy to type them, make an alias alias make='make "LDLIBS=-lm"'
but I don't recommend it - once you start modifying build commands, it's better to create a minimal Makefile for your program.
Dec 20, 2017 at 15:00
According to fedorqui, an alias cannot accept a parameter. Hence, you must create a function in ~/.bashrc
.
acp ()
{
clang "$1".c -o "$1" -l
}
Execute with
acp "filename"
It's said that it is important to use double quotes to avoid just getting the first parameter, i.e. if there's a space in the filename.
Note that I did not test this.
Reference: User Input to Bash Alias?
If I understood you right, the simplest thing would be to make an alias in your .bashrc or .zshrc or whatever shell you are using.
I would not recommend you to edit something somewhere else.
But you could look where you find the program, some programs are scripts, written in perl for example, and can be edited to your will
make
command doesn't have the -l
command and runs clang filename.c -o filename
so i want to include the -l
in the make command so every time i use it runs clang filename.c -o filename -l
clang
command you showed manually?make
runsclang filename.c -o filename
i just want to add options to it so that it runs for exampleclang filename.c -o filename -l
CC
toclang
?CC
toclang