当前位置: 首页 > news >正文

在make类构建系统配置文件中定义函数宏

CMakeLists中定义函数宏

add_definitions(-D'sysctlbyname(name,oldp,oldlenp,ewp,newlen) = -1')

这个写法会报warning:

CMake Warning (dev) at /ssd1t/helloworld/CMakeLists.txt:114:Syntax Warning in cmake code at column 64Argument not separated from preceding token by whitespace.
This warning is for project developers.  Use -Wno-dev to suppress it.

原因是‘=’号前面需要有空格。

写成下面两种都可以:

add_definitions(-D'sysctlbyname(name,oldp,oldlenp,ewp,newlen) =-1')
add_definitions(-D'sysctlbyname(name,oldp,oldlenp,ewp,newlen) = -1')

虽然可以通过,但是在实际编译的时候会报错,原因是cmake并不支持function-style的macro定义:

Preprocessor definitions for compiling a target’s sources.

The COMPILE_DEFINITIONS property may be set to a semicolon-separated list of preprocessor definitions using the syntax VAR or VAR=value. Function-style definitions are not supported. CMake will automatically escape the value correctly for the native build system (note that CMake language syntax may require escapes to specify some values).

Makefile中定义函数宏

直接通过g++命令测试,编译一个helloworld.cpp的文件,报错:

$ g++ -Dsysctlbyname\(name, oldp, oldlenp, newp, newlen\)=1 helloworld.cpp <command-line>: error: expected parameter name, found "1"
helloworld.cpp: In function ‘int main(int, char**)’:
helloworld.cpp:28:7: error: ‘sysctlbyname’ was not declared in this scope28 |   if (sysctlbyname (0, 1, 2, 3, 4) == -1)|       ^~~~~~~~~~~~

修改为下面这样正常,这个宏用单引号包起来:

g++ -D'sysctlbyname(name, oldp, oldlenp, newp, newlen)=1' helloworld.cpp

这里使用了单引号 ' 来包围整个宏定义,可以确保如果宏定义中包含空格或特殊字符,它们会被正确地视为宏定义的一部分。

放到Makefile里面,即:

ifndef HAVE_SYSCTLBYNAME
CXXFLAGS += -D'sysctlbyname(name, oldp, oldlenp, newp, newlen)=-1'
endif

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • Laravel5+mycat 报错 “Packets out of order”
  • CTF-PWN-kernel-栈溢出(retuser rop pt_regs ret2dir)
  • EUC 2024 I. Disks
  • golang 项目打包部署环境变量设置
  • FPGA原型验证(七):如何选择、搭建原型验证平台?
  • Java-关键字(static,final)
  • redis数据库
  • ER模型理论和三范式
  • Infinitar链游新发展新机遇
  • 探索Qt的QVariant:灵活的数据交换机制
  • 无法下载 https://mirrors./ubuntu/dists/bionic/main/binary-arm64/Packages
  • (十六)视图变换 正交投影 透视投影
  • vue3.0(十六)axios详解以及完整封装方法
  • 【React】React18 Hooks 之 useReducer
  • C++--智能指针
  • ES6指北【2】—— 箭头函数
  • [译]CSS 居中(Center)方法大合集
  • ES6 学习笔记(一)let,const和解构赋值
  • happypack两次报错的问题
  • Linux学习笔记6-使用fdisk进行磁盘管理
  • Python 反序列化安全问题(二)
  • Redis 中的布隆过滤器
  • vue-loader 源码解析系列之 selector
  • 第13期 DApp 榜单 :来,吃我这波安利
  • 基于Mobx的多页面小程序的全局共享状态管理实践
  • 判断客户端类型,Android,iOS,PC
  • 实战:基于Spring Boot快速开发RESTful风格API接口
  • media数据库操作,可以进行增删改查,实现回收站,隐私照片功能 SharedPreferences存储地址:
  • elasticsearch-head插件安装
  • ​HTTP与HTTPS:网络通信的安全卫士
  • ​草莓熊python turtle绘图代码(玫瑰花版)附源代码
  • ​插件化DPI在商用WIFI中的价值
  • $GOPATH/go.mod exists but should not goland
  • (22)C#传智:复习,多态虚方法抽象类接口,静态类,String与StringBuilder,集合泛型List与Dictionary,文件类,结构与类的区别
  • (c语言+数据结构链表)项目:贪吃蛇
  • (待修改)PyG安装步骤
  • (黑马C++)L06 重载与继承
  • (六)软件测试分工
  • (入门自用)--C++--抽象类--多态原理--虚表--1020
  • (原創) 如何刪除Windows Live Writer留在本機的文章? (Web) (Windows Live Writer)
  • (转)【Hibernate总结系列】使用举例
  • .bat批处理(九):替换带有等号=的字符串的子串
  • .NET / MSBuild 扩展编译时什么时候用 BeforeTargets / AfterTargets 什么时候用 DependsOnTargets?
  • .NET C# 使用 iText 生成PDF
  • .Net7 环境安装配置
  • .Net8 Blazor 尝鲜
  • [ Algorithm ] N次方算法 N Square 动态规划解决
  • [ARC066F]Contest with Drinks Hard
  • [BZOJ1089][SCOI2003]严格n元树(递推+高精度)
  • [C/C++]数据结构 深入挖掘环形链表问题
  • [c++] 自写 MyString 类
  • [C++随笔录] 红黑树
  • [CTO札记]盛大文学公司名称对联
  • [C语言]-基础知识点梳理-编译、链接、预处理
  • [Day 16] 區塊鏈與人工智能的聯動應用:理論、技術與實踐