Getting base name of the source file at compile time

后端 未结 14 2239
有刺的猬
有刺的猬 2020-12-14 10:07

I\'m using GCC; __FILE__ returns the current source file\'s entire path and name: /path/to/file.cpp. Is there a way to get just the file\'s name file.cpp<

14条回答
  •  温柔的废话
    2020-12-14 10:36

    Just got the same issue; found a different resolution, just thought I'd share it:

    In a header file included in all my other files:

    static char * file_bname = NULL;
    #define __STRIPPED_FILE__   (file_bname ?: (file_bname = basename(__FILE__)))
    

    Hope this is useful to someone else as well :)

提交回复
热议问题