Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

Trying to use (make) with math.h

Writer Matthew Harrington

With gcc command I use the -lm flag with math.h. I trying to use make and I'm getting errors. Is there an lm trick with make and makefiles?

2

1 Answer

If you are new to make and you can compile your code manually on the command line, then I recommend the following steps:

  1. Create a Makefile which basically does exactly what you would do on the command line, e.g.,mybinary: mysourcecode.c gcc -o mybinary -lm mysourcecode.c
  2. Split up compiling and linking your code, e.g.,mybinary: mysourcecode.o ld -o mybinary -lm mysourcecode.o mysourcode.o: mysourcecode.c gcc -c -o mysourcecode.o mysourcecode.c
  3. Make general rules and add use all the fancy features of make, e.g.,

.PHONY: clean
objects := $(subst .c,.o,$(wildcard *.c))

target := mybinary

$(target): $(objects) ld -o $@ -lm $^ %.o: %.c gcc -c -o $@ $< clean: -rm $(target) $(objects)

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy