__FILE__显示带文件名的整个路径

时间:2011-08-04 05:54:09

标签: 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

我只想要文件名而不是整个路径

我正在使用make文件运行此文件,我正在使用此机制

PATH_NOW              = $(shell pwd)
LIB                   =$(PATH_NOW)/../lib

当我需要访问lib文件夹中的任何文件时,我只需要包含

$(LIB)/main.c

1 个答案:

答案 0 :(得分:6)

变化:

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__);
相关问题