xcode 之前没有非静态变量“FrameworkNameVersionString”的外部声明
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28511565/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
No previous extern declaration for non-static variable 'FrameworkNameVersionString'
提问by ArdenDev
I created an iOS framework say CustomFramework and in the CustomFramework.h file created by Xcode has the following contents by default
我创建了一个iOS框架,说CustomFramework,在Xcode创建的CustomFramework.h文件中默认有以下内容
#import <UIKit/UIKit.h>
//! Project version number for CustomFramework.
FOUNDATION_EXPORT double CustomFrameworkVersionNumber;
//! Project version string for CustomFramework.
FOUNDATION_EXPORT const unsigned char CustomFrameworkVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <CustomFramework/PublicHeader.h>
When I build the project, I get these warnings
当我构建项目时,我收到这些警告
No previous extern declaration for non-static variable 'CustomFrameworkVersionNumber'
No previous extern declaration for non-static variable 'CustomFrameworkVersionString'
Any idea why the default framework creation would give these warnings ?
知道为什么默认框架创建会给出这些警告吗?
回答by Nathaniel Johnson
In C family languages this is caused by a variable not explicitly being defined as static
or being declared in a header file as extern
.
在 C 系列语言中,这是由未明确定义为static
或在头文件中声明为extern
.
You have three options for dealing with it.
您有三种选择来处理它。
Place the
static
keyword in front of the definition.static FOUNDATION_EXPORT double CustomFrameworkVersionNumber; static FOUNDATION_EXPORT const unsigned char CustomFrameworkVersionString[];
Create a separate header file with an
extern
definition for each variable.- Suppress the warning with
-Wmissing-variable-declarations
将
static
关键字放在定义前面。static FOUNDATION_EXPORT double CustomFrameworkVersionNumber; static FOUNDATION_EXPORT const unsigned char CustomFrameworkVersionString[];
创建一个单独的头文件,其中包含
extern
每个变量的定义。- 使用以下命令抑制警告
-Wmissing-variable-declarations
This question is similar to this question.
这个问题类似于这个问题。