Xcode4.5/OSX 10.8.2: cannot find <Foundation/Foundation.h>

1,246 views
Skip to first unread message

ocamp...@gmail.com

unread,
Sep 21, 2012, 5:09:24 AM9/21/12
to j2objc-...@googlegroups.com
Steps involved:

Step 1: create the Java class:
public class Hello {
public static void main(String[] args) {
System.out.println("hello, world");
}
}

Step 2: compile the Java class into a .m file:
j2objc Hello.java

Step 3: create the binary file:
j2objcc -c Hello.m

Result:
/Users/miaroba/j2objc-0.5.2/include/JreEmulation.h:25:13: fatal error:
'Foundation/Foundation.h' file not found
#import <Foundation/Foundation.h>

The file JreEmulation.h does reference the missing header file:
24 #ifdef __OBJC__
25 #import <Foundation/Foundation.h>

I checked in this directory:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk

and I found these files:
/System/Library/Frameworks/AVFoundation.framework/Versions/A/Headers/AVFoundation.h
./System/Library/Frameworks/CoreFoundation.framework/Versions/A/Headers/CoreFoundation.h
./System/Library/Frameworks/Foundation.framework/Versions/C/Headers/Foundation.h
./System/Library/Frameworks/JavaVM.framework/Versions/A/Frameworks/JavaNativeFoundation.framework/Versions/A/Headers/JavaNativeFoundation.h

I modified j2objcc like this:
clang $* -I /Applications/...../Headers -I ${INCLUDE_PATH} ${CC_FLAGS} ${OBJC} ${LINK_FLAGS}
but I got a cascading set of missing header files;(

Tom Ball

unread,
Sep 21, 2012, 11:13:47 AM9/21/12
to j2objc-discuss
That's very weird, since after Xcode is installed, clang (the C compiler) can find frameworks without needing a path.  Try copying this to a "Test.m" file:

#import <Foundation/Foundation.h>
#import <stdio.h>

int main(int argc, const char *argv[]) {
  printf("NSFFormattingError: %d\n", NSFormattingError);
  return 0;
}

Then build and run it:

$ clang -o test Test.m
$ ./test
NSFFormattingError: 2048

Notice how the Foundation/Foundation.h file was found with the compiler defaults.  If either of these steps failed, your Xcode installation is botched somehow.  If that's the case, I suggested removing and reinstalling it.

Tom



--
You received this message because you are subscribed to the Google Groups "j2objc-discuss" group.
To unsubscribe from this group, send email to j2objc-discus...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



Vladimir Magaziy

unread,
Sep 22, 2012, 6:18:26 AM9/22/12
to j2objc-...@googlegroups.com
Hi Tom,

The odds are headers are found automatically if command line tools are installed (Xcode 4.4.1 and Xcode 4.5):

$ cd /tmp
$ echo "#import <Foundation/Foundation.h>\
#import <stdio.h>\
\
int main(int argc, const char *argv[]) {\
  printf(\"NSFFormattingError: %d\n\", NSFormattingError);\
  return 0;\
}" > Test.m
$ clang -o test Test.m
clang: Command not found.
$ xcrun clang -v
Apple clang version 4.1 (tags/Apple/clang-421.11.65) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin12.0.0
Thread model: posix
$ xcrun clang -o test Test.m
Test.m:1:9: fatal error: 'Foundation/Foundation.h' file not found
#import <Foundation/Foundation.h>
        ^
1 error generated.
$ xcrun clang -o test Test.m -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk
$ file test 
test: Mach-O 64-bit executable x86_64

I am experiencing the same issues and adding xcrun before clang and make in corresponding makefiles does not help because of that:

$ xcrun make dist
mvn generate-resources dependency:sources
[INFO] Scanning for projects...
<...>
install -C -m 0644 src/main/man/j2objc.1 src/main/man/j2objcc.1 ./dist/man/man1
xcrun clang -c /Users/vm/Desktop/vmagaziy-j2objc/jre_emul/Classes/IOSArrayClass.m -o /Users/vm/Desktop/vmagaziy-j2objc/jre_emul/build_result/Classes/IOSArrayClass.o -ObjC  -Wno-trigraphs -Wunused-variable -Werror -Wno-logical-op-parentheses -Wno-bitwise-op-parentheses -Wreturn-type -Wno-parentheses     -fobjc-abi-version=2 -fobjc-legacy-dispatch  -I/System/Library/Frameworks/ExceptionHandling.framework/Headers -I/Users/vm/Desktop/vmagaziy-j2objc/jre_emul/Classes -I/Users/vm/Desktop/vmagaziy-j2objc/jre_emul/build_result/Classes
In file included from /Users/vm/Desktop/vmagaziy-j2objc/jre_emul/Classes/IOSArrayClass.m:22:
In file included from /Users/vm/Desktop/vmagaziy-j2objc/jre_emul/Classes/IOSArrayClass.h:22:
/Users/vm/Desktop/vmagaziy-j2objc/jre_emul/Classes/IOSClass.h:22:9: fatal error: 'Foundation/Foundation.h'
      file not found
#import <Foundation/Foundation.h>
        ^
1 error generated.
make[1]: *** [/Users/vm/Desktop/vmagaziy-j2objc/jre_emul/build_result/Classes/IOSArrayClass.o] Error 1
make: *** [jre_emul_dist] Error 2

Please notice, the following env variables are not set ALT_SDK_FLAGS, ARCH_FLAGS, ALT_ARCH_FLAGS; so clang does't know where SDKs are located.

Thanks,
- Vova
Reply all
Reply to author
Forward
0 new messages