簡體   English   中英

如何使用條件編譯從其他文件訪問 header 文件中的定義宏?

[英]How can I access the define macro in the header file from other files with Conditional Compilation?

我在 header 文件中有宏。

//header.h
#ifndef HEADER_H
#define HEADER_H

#define vulkan

#endif

我想將此宏與其他頭文件和源文件中的#ifdef 一起使用。

//game.h
#ifndef GAME_H
#define GAME_H

#include "header.h"

#ifdef vulkan
//use vulkan api
#else
//use opengl api
#endif

#endif

我也想在 game.cpp 源文件中使用#ifdef,但我無法從 header 和源代碼中使用#ifdef 訪問 vulkan 宏。 什么是正確的方法?

我也想在game.cpp源中使用#ifdef...什么是正確的方法?

這是一個正確的方法:

// game.cpp
#include "header.h"

如果“header.h”定義了一個宏,那么包含它會將宏定義帶到翻譯單元。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM