gpt4 book ai didi

c++ - 为 ARM mbed 编译 PicoTCP 时未定义对 pico_dhcp_server_initiate 的引用

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:24:02 25 4
gpt4 key购买 nike

我正在从事一个必须使用 PicoTCP 的项目(请参阅 https://developer.mbed.org/users/daniele/code/PicoTCP/,我使用的是该库的旧版本)。在我的 main.cpp 文件中,我有以下代码:

#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);
}

pico_dhcp_server_initiate函数在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 */

而这个方法在pico_dhcp_server.c中实现:

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

编译代码时,出现以下错误:Undefined reference to pico_dhcp_server_initiate(pico_dhcpd_settings *)。我正在使用如下所示的 Makefile 进行编译:

# 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)

我不确定是什么导致了这个错误。我相信 .c 文件没有以某种方式被编译,但我对 Makefile 语法非常陌生。会不会是makefile有问题?有人可以帮我解决这个问题吗?

最佳答案

您遇到的错误不是编译器错误,而是链接器错误。它提示说它没有找到 picoTCP 库中的函数符号,而您没有链接这些函数符号。您需要添加一个 -l<picoTCPlibGoesHere>-L<path to pico TCP lib goes here>我不知道那个库的名称是什么,但它应该命名为 lib.a 。当您将它与 -l 一起使用时标志,离开 lib 和 .a。例如,如果库名为 libpicotcp.a,则标志将为 -lpicotcp .您需要将 -l 标志添加到您的 LIBRARIES 和 -L 到您的 Makefile 中的 LIBRARY_PATHS。

关于c++ - 为 ARM mbed 编译 PicoTCP 时未定义对 pico_dhcp_server_initiate 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30379440/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com