当前位置:网站首页>编译可执行程序的Makefile模块
编译可执行程序的Makefile模块
2022-08-06 02:14:00 【正在起飞的蜗牛】
1、可执行程序的目录结构
demo/
├── bin #存放生成产物
├── include #依赖的头文件
├── lib #依赖的动态库
├── src #源文件、静态库
└── Makefile
2、编译可执行程序的Makefile模块
# 根据平台指定交叉编译工具链
ifeq ($(plat), x86)
CROSS = x86_64-4.8.5-linux-gnu-
else ifeq ($(plat),hi3516dv300)
CROSS = arm-himix200v002-linux-
endif
# 默认的交叉编译工具链
CROSS ?= x86_64-4.8.5-linux-gnu-
CROSS_COMPILE = $(CROSS)
# 定义交叉编译工具
CC = $(CROSS_COMPILE)gcc
CPP = $(CROSS_COMPILE)g++
AR = $(CROSS_COMPILE)ar
STRIP = $(CROSS_COMPILE)strip
RM = rm -fr
CP = cp -rf
# 根目录,也是当前目录
ROOT := $(shell pwd)
# 指定头文件路径
CFLAGS += -I$(ROOT)/include
CFLAGS += -I$(ROOT)/include/common
#编译选项
CFLAGS += -Wall -Werror -O2
CFLAGS += -g
CFLAGS += -c -o
#指定依赖库所在路径
LDFLAGS = -L$(ROOT)/lib
#链接所需库,假设依赖libosal.a
LDFLAGS += -losal
LDFLAGS += -lpthread
#查找所有src目录下.c源文件,只保留文件名不要路径
SRCS := $(wildcard $(ROOT)/src/*.c)
# 源文件.c后缀改为.o
OBJS := $(SRCS:%.c=%.o)
# 要生成的目标文件
TARGET = demo
$(TARGET): $(OBJS)
$(TARGET): $(OBJS)
$(CC) -o [email protected] $^ $(LDFLAGS) #生成可执行软件
cp [email protected] $(ROOT)/bin/[email protected]_nostrip
$(STRIP) [email protected] # 生成strip版本
cp [email protected] $(ROOT)/bin/
clean:
-rm ./demo* ./src/*.o
# Makefile规则:将.c文件编译成.o
%.o : %.c
$(CC) $(CFLAGS) [email protected] $<
# Makefile规则:将.cpp文件编译成.o
%.o : %.cpp
$(CPP) $(CFLAGS) [email protected] $<
编译指令:make plat=xxx or make clean
边栏推荐
- Civil law common sense summary 1
- 浏览器缓存太多怎么办,清理浏览器缓存的方法
- map(自动排序的pair)——STL
- 【树上差分】CF 1076E. Vasya and a Tree
- 1321_一份BootLoader xmodem部分的协议分析
- LeetCode每日两题02:回文数 (均1200道)
- MySQL high-performance construction 1: Centos7+Mysql7.5 builds master-slave replication
- Two file types in typescript70-ts
- The correct posture for Internet workers to write weekly reports
- 互联网职场人写周报的正确姿势
猜你喜欢
typescript72 - Existing type declaration files (type files for third-party libraries)
读书笔记 如何阅读一本书
The difference between session and cookie
CAN turn 4 g remote passthrough record cloud gateway for engineering machinery CAN assign
STP实验
eslint和prettier实现代码格式化
图解 JVM 内存结构
软件工程-大学体育馆管理系统交互图
从采集到存储:时序数据库到底怎么处理时间?
数据治理:走出数据孤岛
随机推荐
第十八天笔记
Nanostar raises more than $200 million for battery material production
typescript74 - create your own type declaration files (provide declaration files for existing js)
Wejo joins MONET alliance to further drive innovation in international mobility
SOAP protocol learning and use
FTX交易所入榜福布斯2022金融科技50强名单
QT:用qt实现一个登录界面
MSTP与STP
软件工程-大学体育馆管理系统类图
关于近期轻量化部署任务的一个小结
STM32与K210串口通信的解码问题(基于正点原子源码)
Compose 进阶挑战来啦!直播预告|8 月 7 日 晚 19:30 与 GDE 导师面对面
阿里云技术专家郝晨栋:云上可观测能力,问题的发现与定位实践
感悟2022年:玫琳凯公布今年上半年以来的奖项、里程碑和成就
The miniPCIe interface CAN card quickly expands the CAN channel for the industrial computer
拦截器通过自定义注解来判断是否拦截
产业园区实现产业集聚的三大举措
MSP430F5529(三)学习记录:芯片超频运行,超频后的串口使用
Raj take-out day01 】 : overall introduction and development environment set up
TS (TypeScript) Binary Operators + , - , * , / , % , << , >> , >>> , & , | , ^ Analysis