How to use LDFLAGS in makefile

前端 未结 3 1432
广开言路
广开言路 2020-11-28 04:26

I am new to Linux OS. I am trying to compile a .c file using a makefile. The math library has to be linked. My makefile looks like this:

CC=gcc
         


        
3条回答
  •  無奈伤痛
    2020-11-28 05:08

    Your linker (ld) obviously doesn't like the order in which make arranges the GCC arguments so you'll have to change your Makefile a bit:

    CC=gcc
    CFLAGS=-Wall
    LDFLAGS=-lm
    
    .PHONY: all
    all: client
    
    .PHONY: clean
    clean:
        $(RM) *~ *.o client
    
    OBJECTS=client.o
    client: $(OBJECTS)
        $(CC) $(CFLAGS) $(OBJECTS) -o client $(LDFLAGS)
    

    In the line defining the client target change the order of $(LDFLAGS) as needed.

提交回复
热议问题