C __文件u uu用文件名显示整个路径
我正在使用C __文件u uu用文件名显示整个路径,c,linux,makefile,C,Linux,Makefile,我正在使用 DPRINTF(ERROR_LEVEL,"ERROR: error found at file: %s line: %d",__FILE__,__LINE__); 它是这样打印的 ERROR: error found at file: /home/jeegar/ full path to that file/main.c line: 102 这里我只想打印 ERROR: error found at file: main.c line: 102 我只想要文件名而不是整个路径 我
DPRINTF(ERROR_LEVEL,"ERROR: error found at file: %s line: %d",__FILE__,__LINE__);
它是这样打印的
ERROR: error found at file: /home/jeegar/ full path to that file/main.c line: 102
这里我只想打印
ERROR: error found at file: main.c line: 102
我只想要文件名而不是整个路径
我用make file运行这个文件,在其中我使用了这个机制
PATH_NOW = $(shell pwd)
LIB =$(PATH_NOW)/../lib
每当我需要访问lib文件夹中的任何文件时,我都会将其包含在其中
$(LIB)/main.c
更改:
DPRINTF(ERROR_LEVEL,"ERROR: error found at file: %s line: %d",__FILE__,__LINE__);
致:
别忘了#包括以防止警告!
DPRINTF(ERROR_LEVEL,"ERROR: error found at file: %s line: %d",basename(__FILE__),__LINE__);