-1

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
  • 5
    Please edit your question to include the relevant section of your makefile, and the specific error(s) you get Jul 10, 2019 at 0:12
  • /usr/include/math.h is the file, and it is part of the libc6-dev package for your architecture.
    – waltinator
    Jul 10, 2019 at 1:49

1 Answer 1

0

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)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .