Apple Mach O Linker警告 [英] Apple Mach O Linker warning
问题描述
我收到这个烦人的警告
Apple Mach-O Linker Warning
Alignment lost in merging tentative definition _searchFlag
我已经在constant.h文件中声明了搜索标记,例如
i have declared the search flag in the constant.h file like this
BOOL searchFlag
过去2天,我一直在解决这个问题,并且尝试了Google提供的所有可能解决方案,但似乎都没有用.
I am stuck up on this issue from the past 2 days and i have tried all the possible solutions from google but none of them seems to be working.
我的应用程序同时支持我添加了设置的armv6和v7拱门,但似乎有点问题,这只是因为bool标志自2天以来就一直困扰我.
My app supports both armv6 and v7 arch for which i have added the settings but this dosent seems to be the problem, its just this bool flag that is biting my head since 2 days.
请帮助我 谢谢
推荐答案
标头中的全局变量在ObjC中是不好的juju;我并没有对全局变量的使用做出判断(因为有时确实需要使用全局变量),但是我将以不同的方式声明它们.
Globals in headers are bad juju in ObjC; I'm not making a judgement on the use of globals (as they truly are sometimes necessary), but I would go about declaring them in a different way.
我能想到的最干净,最简单的方法(也是我的首选方法)是创建一个新类,该类将全局变量的访问器实现为类方法,并将变量本身声明为源文件中的静态变量.
The cleanest and easiest method I can think of (and my preferred method), is to create a new class that implements accessors for your globals as class methods, and declares the variables themselves as static variables in the source file.
myglobal.h
@interface MyGlobal : Object
{
}
+ (BOOL)searchFlag;
+ (void)setSearchFlag:(BOOL)aFlag;
@end
myglobal.m
#import "myglobal.h"
// Static variables
static BOOL _searchFlag = NO;
@implementation MyGlobal
+ (BOOL)searchFlag
{
return _searchFlag;
}
+ (void)setSearchFlag:(BOOL)aFlag
{
_searchFlag = aFlag;
}
@end
使用此方法,访问全局变量就像[MyGlobal searchFlag]
或[MyGlobal setSearchFlag: YES]
一样容易.
Using this method, accessing globals is as easy as [MyGlobal searchFlag]
or [MyGlobal setSearchFlag: YES]
.
这篇关于Apple Mach O Linker警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!