This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

about the link error with arm-none-eabi on the eclipse environment.

Hello all

I'm struggling with link errors, "undefined referencce atan2" as well as all math library. I still dont know why it is occurred these errors. I configured the eclipse compile environment with the gnu arm tool using your doc, application note ver1.2. May you help me?

  • As far as I can see, this just works out of the box. Please see the attached example, that should compile directly if you put it in the Board/nrf6310/ folder, both with SDK version 4.3.0 and 4.4.0. If you still struggle, could you please upload your complete project, including any Makefiles and linker scripts?

    math-lib.zip

  • I can compile the attached math-lib.zip. However if I change the the argument to a variable I get following error.

    main.c:(.text.startup+0x5a): undefined reference to `atan2'
    collect2.exe: error: ld returned 1 exit status
    make: *** [_build/template_project_gcc_s110_xxaa.out] Fehler 1
    

    My main is:

    
    int main(void)
    {	
    	uint8_t idx = 0;
    	double d_idx = 0.0;
    	uint8_t buffer[20];
    	simple_uart_config(0, 17, 0, 16, false);
    	simple_uart_putstring((uint8_t *)"Start\r\n");
    	nrf_gpio_range_cfg_output(8, 15);
    	
    	while (true)
        {
    		idx++;
    		d_idx = (double) idx;
    		float result = atan2(1.0, d_idx);
    		sprintf((char *)buffer, "%f\r\n", result);
    		simple_uart_putstring(buffer);
    		nrf_delay_us(100000);
        }
    }
    

    How can I build this?

    Greetings Markus

  • You're right, I see the same when I tried this modification. To make it work, I had to add -lm to the linking command line. Beware that the place in the line actually matters, but things seemed to work when I put it right before the -o parameter in the final linking: $(CC) $(LDFLAGS) $(C_OBJECTS) $(ASSEMBLER_OBJECTS) $(LIBRARIES) -lm -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out

  • I had this same problem.

    The solution was:

    1- Link with GCC instead of LD (some guys recommend this, dunno where I read it, but seems to work). In your makefile replace

    LD       		:= "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ld"
    

    With

    LD       		:= "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-gcc"
    

    2- Manually add the math lib to your libs

    #link math library.. dunno why this isn't done automatically
    
    LIBS += $(GNU_INSTALL_ROOT)/arm-none-eabi/lib/thumb/libm.a
    

    I don't know why the linker doesn't automatically link the library but this seemed to work for me.

Related