c++ - 在 C++ 中使用 TARGET_IPHONE_SIMULATOR 时出现链接器错误

标签 c++ ios objective-c xcode linker-errors

TARGET_IPHONE_SIMULATOR 宏在我添加到项目的 C++ 源代码中不起作用。不过应该注意,如果我只是用 1 或 0 更改宏,代码就会运行。

这是设置。我一直在转换文件: https://code.google.com/p/ld48jovoc/source/browse/util/tweakval/?r=13使用我在 XCode 中制作的 iOS 应用程序。

除了标题外,一切都几乎相同。

#ifndef TWEAKVAL_H
#define TWEAKVAL_H

#ifdef __cplusplus
extern "C" {
#endif

#include <sys/types.h>

// Do only in debug builds on simulator, this does NOT work on iOS device
#if TARGET_IPHONE_SIMULATOR // replace with 1 or zero to make it work
#  define TV_USE_TWEAKVAL 1
#else
#  define TV_USE_TWEAKVAL 0
#endif


//
// See the thread referenced above for idea of how to implement
// this without the __COUNTER__ macro.

// If we are in a build modethat wants tweakval, and the compiler
// supports it, use it
#if TV_USE_TWEAKVAL
#  define _TV(Val) _TweakValue( __FILE__, __COUNTER__, Val )

//float _TweakValue( const char *file, size_t counter, float origVal );
int _TweakValue( const char *file, size_t counter, int origVal );

void ReloadChangedTweakableValues();

#else
// don't use it
#  define _TV(Val) Val
#  define ReloadChangedTweakableValues()

#endif

#ifdef __cplusplus
}  // extern "C"
#endif

#endif

cpp 文件几乎相同,只是整个文件都包含在#if TV_USE_TWEAKVAL 中。

现在我可以通过代码或在build设置中手动设置这个宏,但我更愿意通过检测预处理器命令让这个东西自动启用/禁用。我的猜测是宏在链接 tweakval 源代码时未被检测到,我不知道我需要更改哪些build设置来解决此问题。

谢谢。

最佳答案

TARGET_IPHONE_SIMULATOR 来自 TargetConditionals.h。您需要#include 该文件。大概您的其他代码通过一些其他路径间接获取它,例如 Cocoa/Cocoa.h

关于c++ - 在 C++ 中使用 TARGET_IPHONE_SIMULATOR 时出现链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18495213/

相关文章:

ios - 使用 CloudKit 和 Swift 一次保存多个 CKRecords

objective-c - 使用 iPhone SDK 获取用户输入的文本并将其保存在网络服务器上

objective-c - 总是使用 isEqual : in Objective-C for object comparison? 是一种好的形式吗

c++ - 为什么bool和_Bool在内存中占用1个字节只能存储0或1?

c++ - 如何在 opencv c++ 中为不同的 Matrix 类型编写方法而不明确指定 Mat 类型

ios - 可以在 iOS 14 上使用 keyboardType emailAddress 在 UITextField 上隐藏预测文本栏吗?

ios - iOS 上的 AdMob 性能差距

ios - iAd 横幅不适用于 iOS 9

C++14 : 2 random generators - one works, 其他没有

c++ - 在 C++ 中拆分硬件相关类