2

I have the following project setup:

1) A main iOS project ('super project')... nothing special here, the project was built on top of one of the default iOS templates from Xcode.

2) A second project ('subproject'), which was created on top of the Static Library template. I added this project to the super project, and created references to it from the superproject in the 'Target Dependencies' and 'Link Binary with Libraries' build phases.

Inside the subproject, I have a C function declaration which looks like this:

ABAddressBookRef myABAddressBookCreateWithOptions(CFDictionaryRef options, CFErrorRef * error);

It's meant as a replacement/proxy of the similarily named function from the AddressBook framework and uses a type (ABAddressBookRef) from that framework. The declaration is stored in a header file, and the implementation exists in the corresponding .m file. To make this type available, I added the framework header to the .pch file of my subproject:

#ifdef __OBJC__
        #import <AddressBook/AddressBook.h>
        #import <Foundation/Foundation.h>
#endif

The following problem occurs:

If I build the superproject (release or debug config), the build fails with this error message:

.../ManagedCFunctions.h:24:1: Unknown type name 'ABAddressBookRef'

Things I've done to fix the issue, or at least get an idea of what's going on:

  • Building the subproject separately works (but a subsequent superproject build fails regardless)
  • Uncommenting the declaration gets rid of the error, but naturally raises an "Implicit Declaration of Function" warning at the calling location
  • Adding the import to the superproject's .pch file does not help
  • Adding the import to the header file of the function directly works, but is not an option in my scenario (parts of the code are autogenerated, and it would be hard to find out which file needs which frameworks)

I suspect that maybe the header file is not processed in Objective-C, but rather C mode, so the imports are ignored due to the #ifdef __OBJC__ macro around the import, but removing it hasn't helped either. I also tried to add #import <Foundation/Foundation.h> to the function's header file to 'suggest' Objective-C mode, and it actually enabled correct syntax highlighting in the file, but hasn't helped for building.

Any suggestions as to why the symbol is found in the .m, but not in the .h file? Or any workaround that does not require adding the import to a specific header file, but globally?

hagi
  • 11,503
  • 3
  • 35
  • 48

1 Answers1

0

Today I found a isuue after I in project -> Info -> Configurations add a configuration file, then I run my project, it goes wrong in my pch file.

It shows that xxx.h not found, I search a lot of solutions, but I can not get the right answer. So I remember that step.

I deleted the configuration file, and my project become normal.

I hope this will be helpful for this kind issue.

aircraft
  • 25,146
  • 28
  • 91
  • 166