Makefile按颜色打印警告/错误等信息
1.在Linux上安装color_cpmpile,地址: git源码地址
2.解压
unzip color-compile-master.zip
3.编译 (注意make前面有“\”)
\make /*使用的是系统的 make 来编译,而非 alias 定义的别名*/
4.安装 (install 的工作是 copy color_cpmpile 到 /usr/local/bin 中,并向 ~/.bashrc末尾添加配置)
sudo \make install
5.此时查看 ~/.bashrc 文件,在文件末尾可以看到新加的配置
alias gcc="color_compile gcc"
alias g++="color_compile g++"
alias make="color_compile make"
6.让新的.bashrc生效
source ~/.bashrc
7.测试
下载的压缩文件中有一个test.c,此时可以用gcc尝试编译
gcc test.c -o test
test.c: In function ‘main’:
test.c:24:2: error: ‘a’ undeclared (first use in this function)
a; // this is an error
^
test.c:24:2: note: each undeclared identifier is reported only once for each function it appears in
在你的电脑上显示的编译信息就会按颜色打印了,如下图所示:
8.要用交叉编译只需要在.bashrc文件末尾添加以下几行命令:
alias gcc="color_compile gcc"
alias g++="color_compile g++"
alias make="color_compile make"
alias mipsel-openwrt-linux-gcc="color_compile mipsel-openwrt-linux-gcc"
alias mipsel-openwrt-linux-g++="color_compile mipsel-openwrt-linux-g++"
我是联发科的芯片,使用mipsel-openwrt-linux-gcc编译工具,你换成自己的就欧克了,修改后记得让.bashrc重新生效。
后记:
我在deepin系统上,先用具有root权限的用户安装了color_compile,make之后正常显示不同颜色的编译信息。然后换了一个没有root用户的账户,make之后没有效果,查了资料发现,.bashrc是每个用户对应一个,把之前具有root权限用户修改过的.bashrc文件拷贝到当前用户的注目录下,让.bashrc重新生效,make就按不同颜色打印了。
此外,之前用没有root权限的账户远程登录查看文件,所有文件都是一样的颜色,有了.bashrc文件后会按颜色显示不同文件类型的。这样来看,.bashrc是和远程shell有关的。
简单记录一下.bashrc知识
在终端上输入
sudo find / -name .bashrc
会找到不止一个结果
/etc/skel/.bashrc
/home/mypc/.bashrc
/root/.bashrc
/etc/skel/.bashrc文件将复制到系统上创建的任何新用户的主文件夹中。
/home/mypc/.bashrc是用户mypc打开shell时使用的文件。
/root/.bashrc是root账户使用的.bashrc。
参考文章:
https://blog.csdn.net/mantis_1984/article/details/54924035