FPGA, SoC, And CPLD Boards And Kits
FPGA Evaluation and Development Kits
5930 Discussions

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

MapleDoi
Beginner
2,174 Views

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

0 Kudos
1 Reply
EBERLAZARE_I_Intel
2,093 Views

Hi,

 

I am unfamiliar with error you are seeing, this seems to be an uncommon issue,

 

Have you try some check up on the issue on Stackoverflow support? There are a lot of possibilities regarding the errors you are seeing, here are some I could find related to yours:

 

https://stackoverflow.com/questions/12824134/undefined-reference-to-pow-in-c-despite-including-math-h

 

https://stackoverflow.com/questions/27475977/c-undefined-reference-to-sqrt-even-with-lm

Reply