Forum Discussion

MapleDoi's avatar
MapleDoi
Icon for New Contributor rankNew Contributor
5 years ago

collect2.exe: error: ld returned 1 exit status Shows up during 'make'

Hi, I am using DE1-SoC. I have a C code which uses pow and sqrt from math.h library. But when i try to make file is shows this error, and says:

undefined reference to 'pow'

undefined reference to 'sqrt'

here is the make file content:

#
TARGET = prognostic2
 
#
ALT_DEVICE_FAMILY ?= soc_cv_av
SOCEDS_ROOT ?= $(SOCEDS_DEST_ROOT)
HWLIBS_ROOT = $(SOCEDS_ROOT)/ip/altera/hps/altera_hps/hwlib
CROSS_COMPILE = arm-linux-gnueabihf-
CFLAGS = -g -Wall   -D$(ALT_DEVICE_FAMILY) -I$(HWLIBS_ROOT)/include/$(ALT_DEVICE_FAMILY)   -I$(HWLIBS_ROOT)/include/
LDFLAGS =  -g -Wall 
CC = $(CROSS_COMPILE)gcc
ARCH= arm
 
build: $(TARGET)
$(TARGET): commandOne.o 
	$(CC) $(LDFLAGS)   $^ -o $@ 
%.o : %.c
	$(CC) $(CFLAGS) -c $< -o $@ 
 
.PHONY: clean
clean:
	rm -f $(TARGET) *.a *.o *~ 

I found that this problem can be solve by inserting -lm in to the command such as:

gcc main.c -o main -lm

But I am not sure how the make file work, which part should I add to solve this problem? I have tried put a few places in the file but seems not working.

Thanks

1 Reply