I'm working on a project where I have to work with PicoTCP (see https://developer.mbed.org/users/daniele/code/PicoTCP/, I'm using 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 is 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'm compiling with a Makefile which 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)
.s.o:
$(AS) $(CPU) -o $@ $<
.c.o:
$(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'm not sure what's causing this error. I believe that the .c file is not being compiled somehow but I'm very new to the Makefile syntax. Could it be that there is something wrong in the makefile? Can someone help me with this?
The error you're getting is not a compiler error but a linker error. It's complaining that it's not finding function symbols which are in the picoTCP library, which you are not linking. You need to add a -l<picoTCPlibGoesHere>
and -L<path to pico TCP lib goes here>
I don't know what the names of that library is but it should be named lib.a . When you use it with the -l
flag, leave off the lib and .a. For example, if the library is named libpicotcp.a, the flag will be -lpicotcp
. You need to add the -l flag to your LIBRARIES and -L to LIBRARY_PATHS in your Makefile.
I've found the solution. In the top of the .c file, was a check whether the constant PICO_DHCPD_SUPPORT
was defined. This was not the case what caused my .c file not to compile and thus the implementation of the function could not be found. Adding this flag to the CC_FLAGS
setting in the makefile, fixed the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With