commands commence before first target. 报错

本文详细解析了在使用make命令编译时遇到的错误原因,并提供了正确的Makefile编写规范。同时,展示了如何利用Makefile实现对源代码变更的自动化编译和更新,确保开发效率和代码一致性。

  在写好makefile 文件后 用make -f filename 命令进行编译的时候报错 




原因是makefile 格式不正确。


改正后的写法:

myapp: main.o  2.o 3.o

gcc -o myapp main.o 2.o 3.o
main.o: main.c  a.h
gcc -o main.c
2.o: 2.c a.h b.h
gcc -o 2.c
3.o: 3.c b.h c.h
gcc  -o 3.c


要求是在写依赖关系的时候,要先写目标的名称,紧跟着一个冒号(:),接着是空格或者是制表符(tab),最后用空格或者制表符分割文件列表。


之后再进行编译通过。



运行文件:




更新b.h 头文件


会更新包含了b.h头文件的部分


删除 2.0


会重新的生成2.o 并更新需要用到2.o的地方


源代码:

 main.c


#include <stdio.h>
#include <stdlib.h>
#include "a.h"
extern void function_two();
extern void function_three();


int main(){


  printf("hello world  main ! \n");
  function_two();
  function_three();
}


2.c


#include <stdio.h>
#include "a.h"
#include "b.h"


void function_two(){


  printf("hello world  fun 2 !  \n");
}


3.c


#include <stdio.h>
#include "b.h"
#include "c.h"


void function_three(){


  printf("hello world fun three ! \n");
}


GCC="aarch64-openwrt-linux-musl-gcc" CXX="aarch64-openwrt-linux-musl-g++" RANLIB="aarch64-openwrt-linux-musl-gcc-ranlib" STRIP=aarch64-openwrt-linux-musl-strip OBJCOPY=aarch64-openwrt-linux-musl-objcopy OBJDUMP=aarch64-openwrt-linux-musl-objdump SIZE=aarch64-openwrt-linux-musl-size CROSS="aarch64-openwrt-linux-musl-" ARCH="aarch64" TARGET_CFLAGS="-Os -pipe -march=armv8-a -mcpu=cortex-a73+crypto -fno-caller-saves -fno-plt -Wa,--noexecstack -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -iremap/ge550v1/qca_95xx_12_2/build_dir/target-aarch64/u-boot-2022.01:u-boot-2022.01 -Wformat -Werror=format-security -fPIC -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,now -Wl,-z,relro" TARGET_LDFLAGS="-L/ge550v1/qca_95xx_12_2/staging_dir/target-aarch64/usr/lib -L/ge550v1/qca_95xx_12_2/staging_dir/target-aarch64/lib -L/ge550v1/qca_95xx_12_2/staging_dir/toolchain-aarch64/usr/lib -L/ge550v1/qca_95xx_12_2/staging_dir/toolchain-aarch64/lib -fPIC -specs=/ge550v1/qca_95xx_12_2/include/hardened-ld-pie.specs -znow -zrelro" no-dot-config-targets=envtools envtools ; make[5]: Entering directory `/ge550v1/qca_95xx_12_2/build_dir/target-aarch64/u-boot-2022.01' Makefile:40: *** commands commence before first target. Stop. make[5]: Leaving directory `/ge550v1/qca_95xx_12_2/build_dir/target-aarch64/u-boot-2022.01' make[4]: *** [/ge550v1/qca_95xx_12_2/build_dir/target-aarch64/u-boot-2022.01/.built] Error 2 make[4]: Leaving directory `/ge550v1/qca_95xx_12_2/package/boot/uboot-envtools' time: package/boot/uboot-envtools/compile#0.14#0.05#0.18 make[3]: *** [package/boot/uboot-envtools/compile] Error 2 make[3]: Leaving directory `/ge550v1/qca_95xx_12_2' make[2]: *** [/ge550v1/qca_95xx_12_2/staging_dir/target-aarch64/stamp/.package_compile] Error 2 make[2]: Leaving directory `/ge550v1/qca_95xx_12_2' make[1]: *** [world] Error 2 make[1]: Leaving directory `/ge550v1/qca_95xx_12_2' make: *** [sdk] Error 2 huaxi@fd4bb9d5f3ca:/ge550v1/Iplatform/build$
最新发布
09-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值