CC = gcc
CFLAGS = -std=c99 -Werror
VPATH = ./src:./include
.MAIN: libstring.so
.PHONY: clean
libstring.o: libstring.c libstring.h
$(CC) $(CFLAGS) -c $< -I ./include -o $@
libstring.so: libstring.o
$(CC) -fPIC -shared $< -o $@
clean:
rm -rf ./*.o ./*.so
In the code snippet above, I’m specifically interested in whether or not I’m using the < automatic variable correctly. This works if the source/prerequisite is a c source file, but seems to fail for object files.
When compiling, I receive the error:
gcc -fPIC -shared -o libstring.so
gcc: No input files specified
Are you sure you’re using GNU make? The code you’ve written will work as you expect in GNU make. However, other versions of make do not support automatic variables in explicit rules, only in suffix (implicit) rules. If you’re using SunOS/Solaris make, for example, then
$<will be empty on an explicit rule.