只打印文名

CMakeLists.txt

c 复制代码
set(CMAKE_C_FLAGS "-O0 -ggdb -D__NOTDIR_FILE__=$(notdir $<)")
// set(CMAKE_C_FLAGS "-O0 -ggdb -D__NOTDIR_FILE__=$(notdir $<) -D__FILENAME__=$(subst $(dir $<),,$<)")

C文件

c 复制代码
#include <stdio.h>

#ifdef __NOTDIR_FILE__
#define M2STR(x) #x
#define M2STR_IMPL(x) M2STR(x)
#define __BFILE__ M2STR_IMPL(__NOTDIR_FILE__)
#else
#define __BFILE__ __FILE__
#endif

void hello()
{
	printf("[%s:%s: %d] hello word\n", "123123", __BFILE__, __LINE__);
}

结果

c 复制代码
liuwen@liuwen-VirtualBox:~/test/cmake/02-1-use_static_lib/build$ ./static_use
[123123:hello.c: 18] hello word
相关推荐
dsyyyyy11012 分钟前
JavaScript变量
开发语言·javascript·ecmascript
z落落1 小时前
C#WinForm 窗体切换与窗体传值(登录跳转案例)+WinForm 窗体传值(从上往下传、从下往上传)
开发语言·windows·c#
allway21 小时前
How to Echo Multiline to a File in Bash [3 Methods]
开发语言·chrome·bash
weixin_462446231 小时前
手把手教你用 Bash 脚本自动更新 /etc/hosts —— 自动绑定网卡 IP 与节点名
开发语言·tcp/ip·bash
一个梦醒了1 小时前
安装git bash选项推荐
开发语言·git·bash
ct9782 小时前
React 状态管理方案深度对比
开发语言·前端·react
数量技术宅2 小时前
2026量化前沿:从Reddit热帖到Python实战,如何用赫斯特指数(Hurst)狙击虚假突破?
开发语言·python
华如锦2 小时前
面了很多 Java转AI Agent方向,一些面试题总结
java·开发语言·人工智能·python·ai
huangdong_2 小时前
电商商品SKU图自动分类技术实现:从DOM解析到智能归档
开发语言
dog2502 小时前
网络长尾延时的重尾本质
开发语言·网络·php