首页 > 解决方案 > 包含的标头的功能未定义

问题描述

我目前正在尝试第一次使用 linux 编译一些代码。在阅读了有关 makefile 的一些基本信息后,我遇到了一个我无法解决的问题。

使用 Tiva Makefile 模板:

# Tiva Makefile
# #####################################
#
# Part of the uCtools project
# uctools.github.com
#
#######################################
# user configuration:
#######################################
# TARGET: name of the output file
TARGET = main
# MCU: part number to build for
MCU = TM4C123GH6PM
# SOURCES: list of input source sources
SOURCES = main.c startup_gcc.c
# INCLUDES: list of includes, by default, use Includes directory
INCLUDES = $(HOME)/embedded/zekeTiva/Include
# OUTDIR: directory to use for output
OUTDIR = build
# TIVAWARE_PATH: path to tivaware folder
TIVAWARE_PATH = $(HOME)/embedded/tivaware

# LD_SCRIPT: linker script
LD_SCRIPT = $(MCU).ld

# define flags
CFLAGS = -g -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp
CFLAGS +=-Os -ffunction-sections -fdata-sections -MD -std=c99 -Wall
CFLAGS += -pedantic -DPART_$(MCU) -c -I$(TIVAWARE_PATH) -I$(INCLUDES)
CFLAGS += -DTARGET_IS_BLIZZARD_RA1
LDFLAGS = -T $(LD_SCRIPT) --entry ResetISR --gc-sections

#######################################
# end of user configuration
#######################################
#
#######################################
# binaries
#######################################
CC = arm-none-eabi-gcc
LD = arm-none-eabi-ld
OBJCOPY = arm-none-eabi-objcopy
RM      = rm -f
MKDIR   = mkdir -p
#######################################

# list of object files, placed in the build directory regardless of source path
OBJECTS = $(addprefix $(OUTDIR)/,$(notdir $(SOURCES:.c=.o)))

# default: build bin
all: $(OUTDIR)/$(TARGET).bin

$(OUTDIR)/%.o: src/%.c | $(OUTDIR)
    $(CC) -o $@ $^ $(CFLAGS)

$(OUTDIR)/a.out: $(OBJECTS)
    $(LD) -o $@ $^ $(LDFLAGS)

$(OUTDIR)/main.bin: $(OUTDIR)/a.out
    $(OBJCOPY) -O binary $< $@

# create the output directory
$(OUTDIR):
    $(MKDIR) $(OUTDIR)

clean:
    -$(RM) $(OUTDIR)/*

.PHONY: all clean

使用这个 makefile,我可以编译和使用 TIVAWARE 路径中任何 .h 文件中的函数。但是,即使我可以包含 INCLUDE 路径中的标头,我包含的标头中的函数也是“未定义的”。由于这不是项目的重点,我决定使用 Tiva 模板,但这确实超出了我的深度。

标签: linuxmakefileundefined

解决方案


显示未定义的引用意味着存在一些链接错误。在 LDFLAGS 中添加包含 TIVAWARE_PATH 和 INCLUDES 路径中的函数定义的库,然后重新编译。


推荐阅读