0

macOS: 10.14.5

XCode: 10.2.1

Clang: 8.0.0

I am able to successfully compile Obj-C with XCode but am getting a fatal error that Foundation.h is missing when attempting to compile from the command line. Any ideas on how to fix this?

$ cat first_program.m                                                                                        
#import <Foundation/Foundation.h>

int main(int argc, const char *argv[]) {
  @autoreleasepool {
      NSLog(@"Hello, World!");
  }
  return 0;
}

$ clang -Wall -framework Foundation first_program.m
first_program.m:1:9: fatal error: 'Foundation/Foundation.h' file not found
#import <Foundation/Foundation.h>
        ^~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

$ clang -v                                                                                                  
clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-apple-darwin18.6.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
l'L'l
  • 44,951
  • 10
  • 95
  • 146
collenjones
  • 510
  • 5
  • 19
  • https://stackoverflow.com/a/15812786/341994 I think you have to show it where Foundation is – matt Jul 21 '19 at 23:35
  • No success yet with that attempt, tried: `/System/Library/Frameworks` and the path in your example. Dumb question: if the framework isn't found, shouldn't the linker throw an error if you pass `-framework Foundation`? Something like `ld: framework not found Foundation`. That's what I see if I try `clang -framework blah` – collenjones Jul 22 '19 at 00:10
  • Have you got the command-line tools property pointed at your Xcode version? OMM the InstalledDir is inside Xcode. – matt Jul 22 '19 at 01:03
  • Also your versions are really strange. I'm on mac os 10.12, way behind you, and Xcode 9.2, way behind you, but my clang is Apple LLVM version 9.0.0, which is ahead of you. So your clang is way way old for what you're doing. This makes me think you have forgotten to install the current command-line tools at all. Go to the developer site and install them, and then go into Xcode Locations pref pane and make sure they are pointed at your Xcode. – matt Jul 22 '19 at 01:07

1 Answers1

4

I suspect since it appears the version clang used is non-Apple headers cannot be located. You can likely tell it where to look for the Foundation framework by adding isysroot to your compile command with the xcrun --show-sdk-path option:

clang -Wall -framework Foundation -isysroot `xcrun --show-sdk-path` first_program.m 
l'L'l
  • 44,951
  • 10
  • 95
  • 146