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

ArdenDev picture ArdenDev · Feb 14, 2015 · Viewed 19.7k times · Source

I created an iOS framework say CustomFramework and in the CustomFramework.h file created by Xcode has the following contents 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 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 ?

Answer

Nathaniel Johnson picture Nathaniel Johnson · Sep 15, 2016

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.

You have three options for dealing with it.

  1. Place the static keyword 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 extern definition for each variable.

  3. Suppress the warning with -Wmissing-variable-declarations

This question is similar to this question.