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

I created an iOS framework such as CustomFramework, and in the CustomFramework.h file created by Xcode, the following content is used by default.

#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 create a 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 creating a default framework will give these warnings?

+6
source share
1 answer

In C family languages, this is caused by a variable that is not explicitly defined as static or declared in the header file as extern .

You have three options to deal with it.

  • Place the static before the definition.

     static FOUNDATION_EXPORT double CustomFrameworkVersionNumber; static FOUNDATION_EXPORT const unsigned char CustomFrameworkVersionString[]; 
  • Create a separate header file with extern definition for each variable.

  • Suppress warning with -Wmissing-variable-declarations

This question is similar to this question .

+2
source

Source: https://habr.com/ru/post/982475/


All Articles