FPGA, SoC, And CPLD Boards And Kits
FPGA Evaluation and Development Kits
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
5147 Discussions

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

MapleDoi
Beginner
1,076 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
995 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-...

 

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

Reply