Undefined link to pico_dhcp_server_initiate when compiling PicoTCP for ARM mbed

I am working on a project where I need to work with PicoTCP (see https://developer.mbed.org/users/daniele/code/PicoTCP/ , I use an older version of this library). In my main.cpp file, I have the following code:

#include "pico_stack.h" #include "pico_dhcp_server.h" int main(void) { // create DHCP server struct pico_dhcpd_settings s = { }; s.my_ip.addr = long_be(0x0a280001); /* 10.40.0.1 */ pico_dhcp_server_initiate(&s); } 

The pico_dhcp_server_initiate function pico_dhcp_server_initiate declared in pico_dhcp_server.h :

 #ifndef _INCLUDE_PICO_DHCP_SERVER #define _INCLUDE_PICO_DHCP_SERVER #include "pico_dhcp_common.h" #include "pico_addressing.h" ... omitted some declarations ... int pico_dhcp_server_initiate(struct pico_dhcpd_settings *setting); #endif /* _INCLUDE_PICO_DHCP_SERVER */ 

And this method is implemented in pico_dhcp_server.c :

 int pico_dhcp_server_initiate(struct pico_dhcpd_settings *setting) { ... } 

When compiling the code, I get the following error: Undefined reference to pico_dhcp_server_initiate(pico_dhcpd_settings *) . I am compiling with a Makefile that looks like this:

 # This file was automagically generated by mbed.org. For more information, # see http://mbed.org/handbook/Exporting-to-GCC-ARM-Embedded GCC_BIN = PROJECT = networking_driver_test OBJECTS = ./mbed-rtos/rtx/TARGET_CORTEX_M/TARGET_M3/TOOLCHAIN_GCC/SVC_Table.o ./mbed-rtos/rtx/TARGET_CORTEX_M/TARGET_M3/TOOLCHAIN_GCC/HAL_CM3.o ./USB_Ethernet/modules/pico_dhcp_common.o ./USB_Ethernet/modules/pico_dhcp_client.o ./USB_Ethernet/modules/pico_http_util.o ./USB_Ethernet/modules/pico_ipfilter.o ./USB_Ethernet/modules/pico_nat.o ./USB_Ethernet/modules/pico_udp.o ./USB_Ethernet/modules/pico_igmp.o ./USB_Ethernet/modules/pico_tcp.o ./USB_Ethernet/modules/pico_simple_http.o ./USB_Ethernet/modules/pico_http_client.o ./USB_Ethernet/modules/pico_icmp4.o ./USB_Ethernet/modules/pico_ipv4.o ./USB_Ethernet/modules/pico_dhcp_server.o ./USB_Ethernet/modules/pico_dev_loop.o ./USB_Ethernet/modules/pico_http_server.o ./USB_Ethernet/modules/pico_dns_client.o ./USB_Ethernet/stack/pico_socket.o ./USB_Ethernet/stack/pico_arp.o ./USB_Ethernet/stack/pico_frame.o ./USB_Ethernet/stack/pico_device.o ./USB_Ethernet/stack/pico_tree.o ./USB_Ethernet/stack/pico_stack.o ./USB_Ethernet/stack/pico_protocol.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Semaphore.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Event.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_List.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Mutex.o ./mbed-rtos/rtx/TARGET_CORTEX_M/HAL_CM.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Task.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_CMSIS.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_System.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Time.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_MemBox.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Robin.o ./mbed-rtos/rtx/TARGET_CORTEX_M/RTX_Conf_CM.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Mailbox.o ./main.o ./USB_Ethernet/USBCDC_ECM.o ./USB_Ethernet/modules/pico_dev_mbed.o ./USB_Ethernet/modules/pico_dev_mbed_usb.o ./USBDevice/USBDevice/USBHAL_RZ_A1H.o ./USBDevice/USBDevice/USBHAL_STM32F4.o ./USBDevice/USBDevice/USBHAL_LPC17.o ./USBDevice/USBDevice/USBHAL_Maxim.o ./USBDevice/USBDevice/USBHAL_LPC11U.o ./USBDevice/USBDevice/USBHAL_LPC40.o ./USBDevice/USBDevice/USBDevice.o ./USBDevice/USBDevice/USBHAL_KL25Z.o ./USBDevice/USBMSD/USBMSD.o ./USBDevice/USBSerial/USBCDC.o ./USBDevice/USBSerial/USBSerial.o ./USBDevice/USBMIDI/USBMIDI.o ./USBDevice/USBHID/USBMouseKeyboard.o ./USBDevice/USBHID/USBKeyboard.o ./USBDevice/USBHID/USBHID.o ./USBDevice/USBHID/USBMouse.o ./USBDevice/USBAudio/USBAudio.o ./mbed-rtos/rtos/Thread.o ./mbed-rtos/rtos/Semaphore.o ./mbed-rtos/rtos/Mutex.o ./mbed-rtos/rtos/RtosTimer.o SYS_OBJECTS = ./mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/retarget.o ./mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/system_LPC17xx.o ./mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/board.o ./mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/cmsis_nvic.o ./mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/startup_LPC17xx.o INCLUDE_PATHS = -I. -I./USB_Ethernet -I./USB_Ethernet/modules -I./USB_Ethernet/stack -I./USB_Ethernet/include -I./USB_Ethernet/include/arch -I./USBDevice -I./USBDevice/USBDevice -I./USBDevice/USBMSD -I./USBDevice/USBSerial -I./USBDevice/USBMIDI -I./USBDevice/USBHID -I./USBDevice/USBAudio -I./mbed-rtos -I./mbed-rtos/rtos -I./mbed-rtos/rtx -I./mbed-rtos/rtx/TARGET_CORTEX_M -I./mbed-rtos/rtx/TARGET_CORTEX_M/TARGET_M3 -I./mbed-rtos/rtx/TARGET_CORTEX_M/TARGET_M3/TOOLCHAIN_GCC -I./mbed -I./mbed/TARGET_LPC1768 -I./mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM -I./mbed/TARGET_LPC1768/TARGET_NXP -I./mbed/TARGET_LPC1768/TARGET_NXP/TARGET_LPC176X -I./mbed/TARGET_LPC1768/TARGET_NXP/TARGET_LPC176X/TARGET_MBED_LPC1768 LIBRARY_PATHS = -L./mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM LIBRARIES = -lmbed LINKER_SCRIPT = ./mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/LPC1768.ld ############################################################################### AS = $(GCC_BIN)arm-none-eabi-as CC = $(GCC_BIN)arm-none-eabi-gcc CPP = $(GCC_BIN)arm-none-eabi-g++ LD = $(GCC_BIN)arm-none-eabi-gcc OBJCOPY = $(GCC_BIN)arm-none-eabi-objcopy OBJDUMP = $(GCC_BIN)arm-none-eabi-objdump SIZE = $(GCC_BIN)arm-none-eabi-size CPU = -mcpu=cortex-m3 -mthumb CC_FLAGS = $(CPU) -c -g -fno-common -fmessage-length=0 -Wall -fno-exceptions -ffunction-sections -fdata-sections -fomit-frame-pointer CC_FLAGS += -MMD -MP CC_SYMBOLS = -DTARGET_LPC1768 -DTARGET_M3 -DTARGET_CORTEX_M -DTARGET_NXP -DTARGET_LPC176X -DTARGET_MBED_LPC1768 -DTOOLCHAIN_GCC_ARM -DTOOLCHAIN_GCC -D__CORTEX_M3 -DARM_MATH_CM3 -DMBED_BUILD_TIMESTAMP=1432213479.57 -D__MBED__=1 LD_FLAGS = $(CPU) -Wl,--gc-sections --specs=nano.specs -u _printf_float -u _scanf_float -Wl,--wrap,main LD_FLAGS += -Wl,-Map=$(PROJECT).map,--cref LD_SYS_LIBS = -lstdc++ -lsupc++ -lm -lc -lgcc -lnosys ifeq ($(DEBUG), 1) CC_FLAGS += -DDEBUG -O0 else CC_FLAGS += -DNDEBUG -Os endif all: $(PROJECT).bin $(PROJECT).hex clean: rm -f $(PROJECT).bin $(PROJECT).elf $(PROJECT).hex $(PROJECT).map $(PROJECT).lst $(OBJECTS) $(DEPS) .so: $(AS) $(CPU) -o $@ $< .co: $(CC) $(CC_FLAGS) $(CC_SYMBOLS) -std=gnu99 $(INCLUDE_PATHS) -o $@ $< .cpp.o: $(CPP) $(CC_FLAGS) $(CC_SYMBOLS) -std=gnu++98 -fno-rtti $(INCLUDE_PATHS) -o $@ $< $(PROJECT).elf: $(OBJECTS) $(SYS_OBJECTS) $(LD) $(LD_FLAGS) -T$(LINKER_SCRIPT) $(LIBRARY_PATHS) -o $@ $^ $(LIBRARIES) $(LD_SYS_LIBS) $(LIBRARIES) $(LD_SYS_LIBS) @echo "" @echo "*****" @echo "***** You must modify vector checksum value in *.bin and *.hex files." @echo "*****" @echo "" $(SIZE) $@ $(PROJECT).bin: $(PROJECT).elf @$(OBJCOPY) -O binary $< $@ $(PROJECT).hex: $(PROJECT).elf @$(OBJCOPY) -O ihex $< $@ $(PROJECT).lst: $(PROJECT).elf @$(OBJDUMP) -Sdh $< > $@ lst: $(PROJECT).lst size: $(SIZE) $(PROJECT).elf DEPS = $(OBJECTS:.o=.d) $(SYS_OBJECTS:.o=.d) -include $(DEPS) -DTOOLCHAIN_GCC_ARM -DTOOLCHAIN_GCC -D__CORTEX_M3 -DARM_MATH_CM3 -DMBED_BUILD_TIMESTAMP = 1432213479.57 -D__MBED __ = # This file was automagically generated by mbed.org. For more information, # see http://mbed.org/handbook/Exporting-to-GCC-ARM-Embedded GCC_BIN = PROJECT = networking_driver_test OBJECTS = ./mbed-rtos/rtx/TARGET_CORTEX_M/TARGET_M3/TOOLCHAIN_GCC/SVC_Table.o ./mbed-rtos/rtx/TARGET_CORTEX_M/TARGET_M3/TOOLCHAIN_GCC/HAL_CM3.o ./USB_Ethernet/modules/pico_dhcp_common.o ./USB_Ethernet/modules/pico_dhcp_client.o ./USB_Ethernet/modules/pico_http_util.o ./USB_Ethernet/modules/pico_ipfilter.o ./USB_Ethernet/modules/pico_nat.o ./USB_Ethernet/modules/pico_udp.o ./USB_Ethernet/modules/pico_igmp.o ./USB_Ethernet/modules/pico_tcp.o ./USB_Ethernet/modules/pico_simple_http.o ./USB_Ethernet/modules/pico_http_client.o ./USB_Ethernet/modules/pico_icmp4.o ./USB_Ethernet/modules/pico_ipv4.o ./USB_Ethernet/modules/pico_dhcp_server.o ./USB_Ethernet/modules/pico_dev_loop.o ./USB_Ethernet/modules/pico_http_server.o ./USB_Ethernet/modules/pico_dns_client.o ./USB_Ethernet/stack/pico_socket.o ./USB_Ethernet/stack/pico_arp.o ./USB_Ethernet/stack/pico_frame.o ./USB_Ethernet/stack/pico_device.o ./USB_Ethernet/stack/pico_tree.o ./USB_Ethernet/stack/pico_stack.o ./USB_Ethernet/stack/pico_protocol.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Semaphore.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Event.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_List.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Mutex.o ./mbed-rtos/rtx/TARGET_CORTEX_M/HAL_CM.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Task.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_CMSIS.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_System.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Time.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_MemBox.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Robin.o ./mbed-rtos/rtx/TARGET_CORTEX_M/RTX_Conf_CM.o ./mbed-rtos/rtx/TARGET_CORTEX_M/rt_Mailbox.o ./main.o ./USB_Ethernet/USBCDC_ECM.o ./USB_Ethernet/modules/pico_dev_mbed.o ./USB_Ethernet/modules/pico_dev_mbed_usb.o ./USBDevice/USBDevice/USBHAL_RZ_A1H.o ./USBDevice/USBDevice/USBHAL_STM32F4.o ./USBDevice/USBDevice/USBHAL_LPC17.o ./USBDevice/USBDevice/USBHAL_Maxim.o ./USBDevice/USBDevice/USBHAL_LPC11U.o ./USBDevice/USBDevice/USBHAL_LPC40.o ./USBDevice/USBDevice/USBDevice.o ./USBDevice/USBDevice/USBHAL_KL25Z.o ./USBDevice/USBMSD/USBMSD.o ./USBDevice/USBSerial/USBCDC.o ./USBDevice/USBSerial/USBSerial.o ./USBDevice/USBMIDI/USBMIDI.o ./USBDevice/USBHID/USBMouseKeyboard.o ./USBDevice/USBHID/USBKeyboard.o ./USBDevice/USBHID/USBHID.o ./USBDevice/USBHID/USBMouse.o ./USBDevice/USBAudio/USBAudio.o ./mbed-rtos/rtos/Thread.o ./mbed-rtos/rtos/Semaphore.o ./mbed-rtos/rtos/Mutex.o ./mbed-rtos/rtos/RtosTimer.o SYS_OBJECTS = ./mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/retarget.o ./mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/system_LPC17xx.o ./mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/board.o ./mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/cmsis_nvic.o ./mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/startup_LPC17xx.o INCLUDE_PATHS = -I. -I./USB_Ethernet -I./USB_Ethernet/modules -I./USB_Ethernet/stack -I./USB_Ethernet/include -I./USB_Ethernet/include/arch -I./USBDevice -I./USBDevice/USBDevice -I./USBDevice/USBMSD -I./USBDevice/USBSerial -I./USBDevice/USBMIDI -I./USBDevice/USBHID -I./USBDevice/USBAudio -I./mbed-rtos -I./mbed-rtos/rtos -I./mbed-rtos/rtx -I./mbed-rtos/rtx/TARGET_CORTEX_M -I./mbed-rtos/rtx/TARGET_CORTEX_M/TARGET_M3 -I./mbed-rtos/rtx/TARGET_CORTEX_M/TARGET_M3/TOOLCHAIN_GCC -I./mbed -I./mbed/TARGET_LPC1768 -I./mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM -I./mbed/TARGET_LPC1768/TARGET_NXP -I./mbed/TARGET_LPC1768/TARGET_NXP/TARGET_LPC176X -I./mbed/TARGET_LPC1768/TARGET_NXP/TARGET_LPC176X/TARGET_MBED_LPC1768 LIBRARY_PATHS = -L./mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM LIBRARIES = -lmbed LINKER_SCRIPT = ./mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM/LPC1768.ld ############################################################################### AS = $(GCC_BIN)arm-none-eabi-as CC = $(GCC_BIN)arm-none-eabi-gcc CPP = $(GCC_BIN)arm-none-eabi-g++ LD = $(GCC_BIN)arm-none-eabi-gcc OBJCOPY = $(GCC_BIN)arm-none-eabi-objcopy OBJDUMP = $(GCC_BIN)arm-none-eabi-objdump SIZE = $(GCC_BIN)arm-none-eabi-size CPU = -mcpu=cortex-m3 -mthumb CC_FLAGS = $(CPU) -c -g -fno-common -fmessage-length=0 -Wall -fno-exceptions -ffunction-sections -fdata-sections -fomit-frame-pointer CC_FLAGS += -MMD -MP CC_SYMBOLS = -DTARGET_LPC1768 -DTARGET_M3 -DTARGET_CORTEX_M -DTARGET_NXP -DTARGET_LPC176X -DTARGET_MBED_LPC1768 -DTOOLCHAIN_GCC_ARM -DTOOLCHAIN_GCC -D__CORTEX_M3 -DARM_MATH_CM3 -DMBED_BUILD_TIMESTAMP=1432213479.57 -D__MBED__=1 LD_FLAGS = $(CPU) -Wl,--gc-sections --specs=nano.specs -u _printf_float -u _scanf_float -Wl,--wrap,main LD_FLAGS += -Wl,-Map=$(PROJECT).map,--cref LD_SYS_LIBS = -lstdc++ -lsupc++ -lm -lc -lgcc -lnosys ifeq ($(DEBUG), 1) CC_FLAGS += -DDEBUG -O0 else CC_FLAGS += -DNDEBUG -Os endif all: $(PROJECT).bin $(PROJECT).hex clean: rm -f $(PROJECT).bin $(PROJECT).elf $(PROJECT).hex $(PROJECT).map $(PROJECT).lst $(OBJECTS) $(DEPS) .so: $(AS) $(CPU) -o $@ $< .co: $(CC) $(CC_FLAGS) $(CC_SYMBOLS) -std=gnu99 $(INCLUDE_PATHS) -o $@ $< .cpp.o: $(CPP) $(CC_FLAGS) $(CC_SYMBOLS) -std=gnu++98 -fno-rtti $(INCLUDE_PATHS) -o $@ $< $(PROJECT).elf: $(OBJECTS) $(SYS_OBJECTS) $(LD) $(LD_FLAGS) -T$(LINKER_SCRIPT) $(LIBRARY_PATHS) -o $@ $^ $(LIBRARIES) $(LD_SYS_LIBS) $(LIBRARIES) $(LD_SYS_LIBS) @echo "" @echo "*****" @echo "***** You must modify vector checksum value in *.bin and *.hex files." @echo "*****" @echo "" $(SIZE) $@ $(PROJECT).bin: $(PROJECT).elf @$(OBJCOPY) -O binary $< $@ $(PROJECT).hex: $(PROJECT).elf @$(OBJCOPY) -O ihex $< $@ $(PROJECT).lst: $(PROJECT).elf @$(OBJDUMP) -Sdh $< > $@ lst: $(PROJECT).lst size: $(SIZE) $(PROJECT).elf DEPS = $(OBJECTS:.o=.d) $(SYS_OBJECTS:.o=.d) -include $(DEPS) 

I am not sure what causes this error. I believe the .c file does not compile in some way, but I am very new to Makefile syntax. Maybe something is wrong in the makefile? Can someone help me with this?

+5
source share
2 answers

I have found a solution. At the top of the .c file there was a check to see if the constant PICO_DHCPD_SUPPORT was defined. This was not so, because my .c file did not compile, and therefore the implementation of the function was not found. By adding this flag to the CC_FLAGS parameter in the makefile, the problem is fixed.

+1
source

The error you get is not a compiler error, but a linker error. He complains that he does not find functional characters that are in the picoTCP library that you are not linking. You need to add -l<picoTCPlibGoesHere> and -L<path to pico TCP lib goes here> . I do not know what the names of this library are, but it should be called lib.a. When you use it with the -l flag, leave lib and .a unlimited. For example, if the library is called libpicotcp.a, the flag would be -lpicotcp . You need to add the -l flag to your LIBRARIES and -L to LIBRARY_PATHS in your Makefile.

+5
source

All Articles