Project Won't Build with .h File

This morning my xCode project stopped building. I'm using XCode 14.2 and Mac OS 12.6.6. A .h file has been in the project for years and the project has been built hundreds of times with this file. Today XCode stopped building the project with two errors;

The .h C header file has only this:

#include <stdio.h>

void func(char *foo, char *bar);

XCode reports an error: Expected identifier or '(' with the underscore unuder the void return type. Obviously this is a spurious error.

Also the analyzer reports: header 'headerfilename.h' is not a member of any targets in the current scheme that build for running. XCode shows that this is in the project in the Identity and Type pane. The project shows this in the pane but with header files the check box is not checked - only .c and .m files, so this is apparently a spurious error as well.

This is weird because I didn't do anything to change this. Also there are a lot of other .h files in the project that are used.

In, order to fix this I have cleared the build folder and rebuilt the project. removed the .h file from the project and built the project, then added it and built it with the .h file in the project. In Identity and Type info pane the .h file shows Target Membership in the project. I removed the whole group with the file and added it again being sure to check the box for target membership but it still won't build this .h file. Other files are added to the group but not this one.

I have experienced a lesser version of this before with .h files but after building the project a couple of times XCode fixed itself. Not this time. XCode got up this morning on the wrong side of the bed and it decided it won't build with this header and I can't add it to the project.

Any suggestions?

Answered by Tlaloc in 759037022

Problem solved:

When XCode crashed I wound up with a single '*' way down in one of my header files. When I looked at it I wouldn't see it. This is weird because I wasn't doing anything with that file. I probably did it myself but I don't know how. Then the preprocessor would add the header file to the source code file and when it built it would report an error but not in a way that told me what was wrong. Another strange thing is that it reported this error in all of my .c and .m files so when I followed johnSOS' very excellent advice to preprocesses some files and look at the output, I didn't happen to look at ones with the messed up header file. So, XCode was very unhelpful in letting me find the problem.

Also strange, DTS can't build my sample project without #import <Cocoa/Cocoa.h> in one of my .h files so the .m file knows about Cocoa. This looks like a bug because the project includes an appname_Prefix.pch file with:

#ifdef OBJC #import <Cocoa/Cocoa.h> #endif

This is supposed to be a prefix file for all source files in the target so they know about Cocoa. This is weird.

Finally one of my source files wouldn't compile for DTS without <Foundation/Foundation.h> in its header. This is also strange because it did for years for me. Maybe I should #import this in the .pch file as well just to be safe.

Finally DTS suggests that I use DIF to file errors. I've never had to do this before but I will.

Thanks to everyone for helping me with this issue.

Now XCode has completely lost its mind and is randomly reporting the spurious Expected identifier error all over the place in files that include a header.

Things have gone from horrible to worse. Each time I build my project XCode is randomly deciding that one of the headers has the spurious "Expected identifier or '('" error and that the functions in the .c or .m file are undefined. Each time I build the project a different file is affected and there is a different number of errors.

Also it has decided that it doesn't know what an enum declaration is.

I got really desperate: I cleaned the build folder and closed XCode. I restarted my machine. The project was working yesterday so I restored yesterday's .xcodeproj file with Time Machine. No, XCode has completely failed and it's getting worse. The version of XCode I'm using (14.2 (14C18)) was installed in December. Is there a newer one?

Don't you hate it when this happens? Yes, there is a newer version of Xcode (14.3.1), but I doubt that the problem is that you are not using the latest version, given that your project didn't change. I suggest you take a deep breath, boot into Recovery mode and run Disk First Aid. Perhaps something is messed up in your file system.

Booting in safe mode didn't help. Disk First Aid thinks that everything is OK. EtreCheckPro found a suspicious problem: Yesterday XCBBuildService, a component of XCode, crashed. My best guess is that when this happened it killed my project. How would I fix this?

Searching for XCBBuildService I found several posts on Stack overflow from people with similar problems. They solved them by deleting the derived data in their ~/Library/Developer/DerivedData folder. Would this help?

I can cd the directory to this with the terminal command ~/Library/Developer/XCode but it looks like I can't do anything with the contents of the DerivedData directory: Permission denied.

I could open the DerivedData Directory in the Finder and delete the data. Should I do it?

After I delete the derived data, XCode will re-index and rebuild the project but it is still dead. I thought about upgrading to the newer version of XCode but it can't be installed on my Intel iMac. Some projects still work but the two really important ones are dead. Unless someone has some idea of how to solve this problem I can't develop software for the Mac.

I filed a DTS technical service request.

More bad news: It isn't just the one .h file. If I select any .h file and use Product>Perform Action>Compile File I get an error 'headerFileName.h' is not a member of any targets in the current scheme that build for running. So it appears that the target is broken and doesn't know it has any headers. If I delete the target and re-build the project will XCode create a new target? Maybe one that works?

After spending a great deal of time trying to diagnose and fix this problem I have been able to ascertain that:

On June 15th XCBBuildService, a component of XCode, crashed. This killed Xcode.

Now I can’t build my projects because even though the header files in the projects are installed correctly and have the correct target membership, the analyzer thinks that they are not in the build scheme of the project.

When I try to build a project Xcode will fail to build as soon as it encounters a header file. It will report the spurious error: Expected identifier or ‘(‘ as soon as there is any text after any #includes. This is function prototypes but also statements like enum.

Then it will report an error of undefined functions in a file where the prototypes are in the .h file that it now can’t build.

I can’t install the latest version of Xcode because I’m using an Intel iMac. How in the world can I possibly fix this?

I got a version of XCode from December when I installed this version using Time Machine. This doesn't help.

Since the analyzer thinks that the .h files aren't in the scheme I deleted the scheme and built a new one. No help either.

Finally I decided to do the really difficult thing. I created a new XCode multiple document project and began to carefully add the source files to it. I got about half way through before XCode failed to add a .h file to the project. After doing this several times it added the .h file but it won't build because it generates the dreaded Expected identifier or '(' error at the first ocurance of any text in the file after the compiler directives. This is HORRIFYING.

XCBBuildService is crashing. I saved the report as text but this site won't let me attach the file. The error reported in the file is:

Error Code: 0x00000004 (no mapping for user data read).

I'm hoping to get some help here because I'm not getting a response from Developer Technical Support.

Theoretically there is somewhere to get older versions of development software so I could reinstall XCode 14.2 but I can't find it on the developer site. Does anyone know how to do this?

I found the download. Maybe re-installing XCode will help.

Re-installing XCode doesn't help.

Project Won't Build with .h File
 
 
Q