I'm developing a Command-line tool in Xcode (exercise for university), but the editor is unable to include the standard C header file that provides I/O and files functions. When I compile, the build succeeds, so the problem is just the editor showing annoying errors. I tried installing the Xcode 11 Command-line tools from the Apple Developer site and also the ones for Xcode 11.2 beta. I can't seem to find the ones for Xcode 11.1, which is the version I'm using at the moment (build 11A1027).
Asked
Active
Viewed 463 times
0
-
1Probably not your immediate problem, but note that it should be `FILE *fp;` (not `FILE fp`). Also, what have you got in lines 1-8 that you're not showing us ? – Paul R Oct 19 '19 at 13:26
-
Yes, I know, just wrote something after FILE to show the error, didn't even notice. ;) I'm sorry, I thought of taking the screenshot of just the interesting part, lines 1-8 are the usual comments that Xcode puts in. Just comments anyway. – Prec99 Oct 19 '19 at 13:27
-
How did you create the project for this? Out of curiosity, using Xcode 11.0 (11A420a), I created a new command line project and it worked. I create a lot of command line tools in Xcode and haven't run into this problem before. Note I do realize I'm not using the same version you are. – Mobile Ben Oct 19 '19 at 16:13
-
I created it in Xcode, New project and everything. I've run in this problem with 11.0 too, then I updated hoping in a fix, but that didn't work. I do create a lot of command line tools myself, and it happens most of the times. Not always though, which makes the error even more strange. – Prec99 Oct 19 '19 at 16:34
1 Answers
0
Obviously, Xcode does include stdio.h
. But the problem is that valid stdio.h
code can sometimes report lots of errors within the Xcode IDE.
I experienced the same behavior you describe. In my case, even when the code was fixed, Xcode still reported alleged “errors”. Interestingly, even though the IDE reported these errors, it would build the app fine.
For me, this incorrect error reporting within the IDE went away when I emptied the “derived data” folder:
locate the derived data folder by go to preferences command+,, choose “Locations”, and then click on the arrow next to the “derived data” path:
quit Xcode;
empty the “derived data” folder; and
restart Xcode.
And, of course, add the missing *
:
#import <stdio.h>
int main(int argc, const char * argv[]) {
FILE *fp;
fp = fopen("test.txt", "w");
if (fp) {
fputs("example\n", fp);
fclose(fp);
}
return 0;
}

Rob
- 415,655
- 72
- 787
- 1,044
-
I did everything you said, I emptied it many times, but whenever I open the project (or create a new one) the error shows up again and the folder is back to its original status. Thanks for the suggestion though. – Prec99 Oct 19 '19 at 16:31