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.

Today I upgraded to MAC OS 12.6.7. After I restarted my mac XCode asked me to install additional shared components. I did. This didn't help.

According to XCode Help You can go to File > Project Settings... This will show a panel that will have a pop-up menu to select either the old or new Build System. This sounded promising but unfortunately In XCode 14.2 there isn't really any pop-up menu to do this. No help from DTS.

I moved everything to a new 24" Apple silicon iMac, hoping that it would help. I installed XCode 14.3.1. During the installation from the App Store it checked my old version of XCode and it said that it was damaged and recommended that I move it to the trash - good idea, since it was FUBAR. After I installed XCode 14.3.1 I tried to build my most important project it still won't build, With the same errors - it can't build any .m or .c file with a #include or #import any .h. Any .h header file in the project won't build with a spurious error: Expected identifier or '(' at the first line of text after the #includes. Then the file in which the .h is #included won't build:undeclared function (in the .h file that won't build).

The newer version of XCode reports a different error: missing input '/Users/myname/Library/Developer/XCode/DerivedData/appname-gobldegookishkabibble/Build/intermediates.noindex/appname.build/Debug/appname.build/Objects-normal/arm64/sourcecodefilename.o'and no rule to build it

Of course this is not helpful. I filed a DTS request for help on June 16th - 19 days ago but all I have received is a response saying that DTS is swamped (I'll bet) and that when the representative assigned to this case has some time I will get a response. I'm guessing that this will be never.

I guess that when XCode decided to commit suicide it also killed all of my projects. On difference is that I don't see an XCBBuildService crash in the Console.

Now there is a little good news. This computer has a number of small projects used to develop relatively small pieces of code for use in larger programs. These will now build and run. I don't know if I can add new .h, .c or .m files to them but at least they build and run.

Since there is some problem with files in the files/folders created for my program that I need to update, could I delete everything related to the project in my ~/Library/Developer/XCode/DerivedData/appname-ishkabbiblegobbldegook folder? Or at least the ishkabibble/Build folder? When you create and build a new project, XCode creates these so will it create the folders/files it needs or will I be even more screwed than I am now?

I deleted the derived data of some small projects to see if XCode will re-create it and run. Yes it will. Doing it on my main project it will re-create the derived data but my project still won't build. It still reports the spurious errors.

I decided to create a new project. This was very difficult because XCode wanted me to a lot of things that weren't required before and aren't described as needed in the documentation, for example put the project in a workspace and use a hierarchy with the .xcodeproj in a folder with the source code files in a folder in the same parent folder. I still have the same problem. I can drag a .h file from the source code files to the project navigator. XCode asks if I want to add it to the target. I check yes but when I build the project I get two errors: in the .h file the first character in the first line of code is underscored and there is an error "Expected identifier or'('. The second error is if I analyze or compile the .h file: "'headerfile.h' is not a member of any targets in the current scheme that build for running". When I use the attributes inspector to look at the target membership of the .h file the checkbox for target membership is not selected.

Obviously these are spurious errors. I can't build any .c or .m file with the header #included or #imported because XCode won't add it to the target.

It has now been three weeks since I filed a Developer Technical Service request so my speculation that "as soon as I have time" means never is probably correct.

Since I haven't been able to get any help anywhere I might have to accept the fact that after about 25 years of programming on the Mac I am now an ex-developer.

I've had similar problems, which is why I found this thread. Unfortunately, I can see it's really just you streaming your journey through this problem without much help from the community. I suggest you supply some more information about your project.

It appears you are trying to compile a C file and are specifically talking about C headers. Have you tried looking at the preprocessor output? I once had the exact same problem and I discovered that my function name corresponded to a macro definition in some standard header. My function name was StrLength, so my function name was replaced by "int" in the preprocessor output. I added #undef StrLength and everything compiled fine.

In your case, your example is void func(...). Is that literally your code or is the function name something else? I suggest you include actual code if you the best help.

Is you project entirely comprised of only C files? Are you using Objective C? Are you bridging Objective C and Swift?

In my project, I have low level code in C. Then a layer of Objective C on top of that. Then Swift code for my model on top of that. Finally, there's SwiftUI code that uses the Swift model. In order to mix the Objective C and Swift, I needed a bridging header. I was getting hundreds of phantom errors at one point, even though my builds were successful. Turns out that it was related to the SwiftUI previews, which also are compiling the same code in its own builds.

I solved this problem by including more header files in the bridging file. I had included only the Objective C headers because the C headers were all included indirectly. I explicitly added all of the C headers and my phantom errors went away.

Believe me, I know how frustrating this can be! But you might get more help by providing more information about your project and supplying more actual source code.

The project has both C and Objective C source code files. XCode won't build either .c or .m files because it doesn't include the .h files in the target so the functions in the .c and .m files are undefined. Also there are a few other weird errors like: NSString - unknown type. This is probably also a no headers error.

There is no Swift.

On June 15th I changed the location or an NSTextField in a .xib. XCode blew up and never worked again in spite of my extraordinary efforts to fix it, checking everything, reading the documentation, rebuilding everything and even buying a new Apple Silicon Mac (which I needed to do anyway), knowing that there is not really any help for Mac developers.

It is VERY unlikely that there is a name collision. This project was created in about 2010 so it would have been obvious by now. Also if you add the same file to an xcodeproj twice it will generate a warning so it is likely that XCode will report this as an error.

Here is an example of real source code in a .h file:

#include <stdio.h>

void cocoaAlertForC(char *errorType, char *message);

XCode underscores the void declaration and reports Expected identifier or '(' - obviously a spurious error. It does this with or without the #include.

There's just no way to Force XCode to recognize header files in the Build folder with the old Project or in the target in the newly created project.

DTS is not interested in helping me.

I feel like I have to give up.

Good news: Apple DTS has responded to my request. I have already tried everything he suggested and more so I'm not optimistic but at least he can try to see if my projecs will **** up on his machine.

I'm assuming that when you say "...it doesn't include the .h files in the target...", you mean click on the file in the project navigator and then click on the Target Membership checkbox in the info pane. If that is what you mean, I can tell that you do not do that with header files. I'm using Xcode 14.3 and it won't even let me. You also don't do that with the Info file, although for some reason Xcode lets me, but that causes build problems.

It seems like you've somehow screwed up the paths to your files. Personally, I keep my implementation and header files together in the same folder. (I know some old school programmers like to keep them separated by file type.) I also group my files in the navigator to match the subfolders containing the files. That's how I maintain my sanity. So in my project that is only Objective C and C (no Swift), it looks like this:

And clicking on that small right pointing arrow icon after the filename takes me to the file in the Finder. I think that's key. If you click on that arrow and it doesn't take you to the actual file then something is screwed with your paths.

That aside, you've obviously been writing C for awhile now and you must know that an error on a line does not mean that there is an error on that line. It's probably an error that came before that line in the compile. If you get the header file locations sorted out and still have this compile error then I would look at the preprocessor output. That is what is actually being compiled, not the source code you're looking at.

Also, compile just the C implementation file and follow the includes from the implementation file in the order they are included. There's probably a problem earlier in the compile of the implementation file.

I keep all of my source code files and header files together in groups in the project folder. I can delete them from the project and then drag them back into the project. They will appear in the project navigator but they won't build. Spurious error: Expected identifier or '(' in the headers and the analyzer thinks that the header file is not a member of any targets in the current scheme that build for analyzing. I tried to add some headers individually and check the target box to force XCode to include them in my project but as you say, you can't and shouldn't do this.

I didn't change the inclusion of any .h .c or .m files. These are in the project folder. Adding them using the several options won't fix this. On June 15th I moved an NSTextField in a .xib a few pixels. When I built the project it and all of my projects stopped working on three versions of XCode and two Macs - Intel and Apple Silicon. XCBBuildService - a component of XCode crashed at this time. On the new M1 iMac this is not happening.

To verify that it isn't the project files, I created a new project (several times) and started adding files, carefully following the directions in the XCode documentation. Of course the documentation is inaccurate, for example I couldn't add some illustrations to the project without putting it in a workspace. They won't build. I'll study your post and see if I've missed anything.

Project Won't Build with .h File
 
 
Q