对多个源文件使用一次#define [英] Using #define one time for multiple source files

查看:264
本文介绍了对多个源文件使用一次#define的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Visual C ++中是否有一种方法可以#define cpp文件中的某些内容,并将其也定义在其他cpp文件中?

Is there a way in Visual C++ to #define something in a cpp file and have it defined in other cpp files as well?

推荐答案

至少有两个选项:


  • 将定义放入头文件并将该头文件包含在所有源文件中其中需要定义

  • 使用 / D 编译器选项以定义宏(也可以在 C / C ++下的项目属性中进行设置- >预处理程序->预处理程序定义

  • Put the definition into a header file and include that header file in all the source files in which you need the definition
  • Use the /D compiler option to define the macro (this can also be set in the project properties under C/C++ -> Preprocessor -> Preprocessor Definitions)

这篇关于对多个源文件使用一次#define的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆