How to change compilation flags for MyFramework_vers.c in Xcode?

If Apple Generic Versioning support is enabled, Xcode automatically generates the MyFramework_vers.c file in DERIVED_SOURCES_DIR , which contains the version string and number, defined as const unsigned char[] and const double .

However, if -Wmissing-variable-declarations enabled (the -Weverything part), this triggers warnings

no previous extern declaration for non-static variable 'MyFrameworkVersionString'
no previous extern declaration for non-static variable "MyFrameworkVersionNumber"

Possible solutions seem to be:

  • add -Wno-missing-variable-declarations to cflags for this file
  • add extern declarations over variable definitions
  • add #import , which pulls extern declarations from the umbrella header

But I cannot figure out how to do this, since the file is in DerivedSources and is not part of the compilation sources phase. What am I missing?

(I found the VERSION_INFO_EXPORT_DECL parameter that would allow me to flag extern variables, but then I get the warning "extern variable has an initialization warning", starting with -Wextern-initializer , so this does not help).

+1
source share
1 answer

I do not know how to change the compiler arguments for this file, but you can turn to the warning by abusing VERSION_INFO_EXPORT_DECL . Set the value for the newline character, and then #import "HeaderWithExternDeclarations.h" and another literal newline. In pbxproj it should look something like this:

 VERSION_INFO_EXPORT_DECL = "\n#import \"MyFramework.h\"\n"; 

If you want to import a header containing Objective-C, you will also need to change VERSION_INFO_FILE to a value with the extension .m, for example MyFramework_vers.m, so the generated file will be compiled as Objective-C source.

Alternatively, you can use the same hack to insert a pragma to turn off the warning:

 VERSION_INFO_EXPORT_DECL = "\n#pragma clang diagnostic ignored \"-Wmissing-variable-declarations\"\n"; 
+3
source

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


All Articles