linux - 包含的标头的功能未定义
问题描述
我目前正在尝试第一次使用 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 模板,但这确实超出了我的深度。
解决方案
显示未定义的引用意味着存在一些链接错误。在 LDFLAGS 中添加包含 TIVAWARE_PATH 和 INCLUDES 路径中的函数定义的库,然后重新编译。
推荐阅读
- docker - 来自 gitlab-ci docker 的 SSH 在“SSH2_MSG_KEX_ECDH_REPLY”上失败
- loops - 包含多个 if 语句的单个循环或多个内部带有循环的 if 语句?
- sql - sqlite如何用前一个值替换null
- shell - RHEL RPM 规范安装后 %post 未获取 shell 脚本
- java - 用于接受 Multipart 文件的 DELETE 方法的 Mockmvc
- jenkins - Jenkins 在 Jenkinsfile 中使用导入
- bash - 如何在环境变量中捕获 bash 命令组(大括号)的输出
- python - 如何使用两个字段作为组合字段对 django 查询集进行排序
- python - 如何从熊猫数据框中绘制坐标在同一条线上?
- airflow - 如何在气流中创建 Hive 连接到特定数据库?