- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我目前正在开发一个项目,涉及7个文件:main.cpp
、GpioInterface.h
、GpioInterface.cpp
、Utility.h
和 Utility.cpp
。
基本上,在 main.cpp
文件中,我使用 #define BOARD_TYPE WHATEVER
声明了电路板类型,然后在 GpioInterface.h
中,我定义了一些定义此宏时的值。
看起来像这样:
主要.cpp:
#define __USE_BOARD_ WHATEVER // This should go in an external file in the future
#ifdef __USE_BOARD_
// Define some stuff
#endif
#include "GpioInterface.h"
#include "Utility.h"
// main function here
Gpio接口(interface).h:
#ifndef GPIO_INTERFACE_H
#define GPIO_INTERFACE_H
#include <stdint.h>
#include <stdio.h>
#ifdef __USE_BOARD_
enum GPIO_PIN_MODE {
GPIO_PIN_MODE_OUTPUT = 0x00,
GPIO_PIN_MODE_INPUT = 0x01,
};
enum GPIO_PIN_STATE {
GPIO_PIN_STATE_LOW = 0x00,
GPIO_PIN_STATE_HIGH = 0x01,
};
#endif // __USE_BOARD_
// some other stuff
#endif // GPIO_INTERFACE_H
实用工具.cpp:
#include "Utility.h"
#include "GpioInterface.h"
void someFunction() {
GPIO_digitalWrite(2, GPIO_PIN_STATE_HIGH); // Write HIGH in pin 2
}
编译时,GpioInterface.h
文件出现以下错误 'GPIO_PIN_STATE_HIGH' was not declared in this scope
。
知道如何使 GpioInterface.h
中定义的枚举对 Utility.cpp
可见吗?
谢谢!
最佳答案
main.cpp 编译正确由于
#define __USE_BOARD_ WHATEVER // This should go in an external file in the future
一开始。在 Utility.cpp 中你没有那个定义,所以包含“GpioInterface.h”没有定义枚举。
关于c++ - #ifdef 不接受枚举定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47885235/
在下面的 C 代码摘录中,SUPPORT_MULTI_DNS_SERVER 是否仅在定义 ProductName 时执行? #ifdef //do things here #ifdef SUPPO
我有一些 C++ 代码,其中有一堆 #ifdef WIN32,否则我们假设它的 IOS 代码。但是,我现在正尝试将相同的 C++ 代码用于 Android 端口。 #ifdef WIN32 是否有某种
我看过一些用于处理不同操作系统的样板头文件代码,如下所示: #ifdef __WIN32 //windows #elif __linux //linux #elif __unix
在 C++ 中,是这样的: #ifdef A && B 同: #if defined(A) && defined(B) ? 我以为不是,但我无法通过我的编译器 (VS2005) 找到差异。 最佳答案
我正在尝试理解 #ifdef 宏。下面的示例代码。 getval(int val) { if(val==0) { #ifndef PKT #define PKT #endi
我有一个包含如下命令的 Makefile: #Makefile hello: echo 'hello' echo $(TAG) ifdef TA
我正在努力让 Log4D 在 Delphi XE4 中工作,并且遇到了一些编译错误,因为它在 use 子句中找不到 Contnrs,除非我将它移到定义它的 ifdef 之外。 {$IFDEF DELP
是否可以在一个 {$IFDEF} 指令中定义多个条件? 我想要这样的语法: {$IFDEF Condition1 OR Condition2} DoSomething; {$ENDIF} {$IFDE
我经常看到这用于使模块与 GHC 和 Hugs 兼容,但谷歌并没有帮助我了解更多关于它的信息。 我可以在条件中放什么?我可以根据正在使用的“基础”版本来制作模块的一部分吗? 编辑 3/2017 :这是
在调试gen_server模块的时候,我想记录更多的细节状态。 init()-> put(?COMPLETED_COMMANDS,[]), -ifdef(DEBUG). put(?DE
在调试gen_server模块的时候,我想记录更多的细节状态。 init()-> put(?COMPLETED_COMMANDS,[]), -ifdef(DEBUG). put(?DE
我知道已经有一篇与我的类似的帖子( C++ `ifdef` with concatenation of macros values ),但该帖子相当旧,提供的解决方案对我不起作用,因为我无法设置我想要
我在编译过程中传递了一个macto: % gcc -DIDENT="abcd"app.c 在编译宏时检查宏的正确方法是什么?例如,以下内容有效,但会引发警告: #ifdef IDENT == "abc
我有一个回调函数数组。仅当定义了“SOMETHING”时才应使用一个函数。在数组中包含 #ifdef 是否正确,例如: void (*const array[])(void) = { func
是否可以在这样的 if 条件中使用 #ifdef 宏? if(Something() || SomethingElse() #ifdef __TEST__ || SomethingTest()#end
我有一个 QT 输入监听器类,它在运行的 QCoreApplication 中发出 stdin 输入信号。我想在 Windows 和 Linux 上都使用它。 我目前的方法是在 header 和 cp
我看见了 #ifdef code; #endif 要包含在内,但我找不到它在它包含的任何 header 中定义。是否有任何其他机制可以定义 token ? 最佳答案 首先,有些宏是由编译器隐式定义的
这个类是在我的项目中定义的: class B : public A { public: A& Get_a(int type); ... protected: #ifdef COMPILE_F
我正在以编程方式创建 UniversalApp。在我的应用程序中,我有 2 个常量类,并且在设备的基础上我想导入我的常量类。但它总是打开“Constants_iPad”类。甚至条件为真或假。 #ifn
我正在开发一个共享库,它有一些头文件,其中包含函数模板,例如: #ifdef somecompilerflag #define FUNCTION functionA #else #define FUN
我是一名优秀的程序员,十分优秀!