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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:39:12  来源:igfitidea点击:

No previous extern declaration for non-static variable 'FrameworkNameVersionString'

objective-cxcodeios-frameworks

提问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 staticor being declared in a header file as extern.

在 C 系列语言中,这是由未明确定义为static或在头文件中声明为extern.

You have three options for dealing with it.

您有三种选择来处理它。

  1. Place the statickeyword in front of the definition.

    static FOUNDATION_EXPORT double CustomFrameworkVersionNumber;
    
    static FOUNDATION_EXPORT const unsigned char CustomFrameworkVersionString[];
    
  2. Create a separate header file with an externdefinition for each variable.

  3. Suppress the warning with -Wmissing-variable-declarations
  1. static关键字放在定义前面。

    static FOUNDATION_EXPORT double CustomFrameworkVersionNumber;
    
    static FOUNDATION_EXPORT const unsigned char CustomFrameworkVersionString[];
    
  2. 创建一个单独的头文件,其中包含extern每个变量的定义。

  3. 使用以下命令抑制警告 -Wmissing-variable-declarations

This question is similar to this question.

这个问题类似于这个问题