gcc support __FILE_NAME__ macro

Fri, 2023-06-02
本文最后修改于 Tue, 2023-06-06
gcc support __FILE_NAME__ macro

2023-06-06 update:

windows does not support shell basename. Makefile native support basname like, it’s notdir.

contents

Since gcc-12, gcc native support __FILE_NAME__ macro. ref

Here we provide some methods to make gcc version lower than 12 support __FILE_NAME__:

Makefile:

CXX_FLAGS+=-D__FILE_NAME__=\"$(notdir $<)\"

test: test.c
    gcc-7 $(CXX_FLAGS) $<

Qt pro:

DEFINES += '__FILE_NAME__=\\\"$(notdir $<)\\\"'

Some information of macro is at here.

avatar
除非注明,本博客所有文章皆为原创。
本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。