CLang compilation failed - objective-c

I faced following error while compiling main.m (Objective-C)
I am using makefile to build this file.
/Volumes/Xcode/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -Wall -DDEBUG=1 -g -o main.o main.m -mmacosx-version-min=10.8 -F/Volumes/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/
In file included from main.m:9:
In file
included from /System/Library/Frameworks/Cocoa.framework/Headers/Cocoa.h:12:
In file included from /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:138:
In file included from /System/Library/Frameworks/Foundation.framework/Headers/NSAppleEventDescriptor.h:7:
/System/Library/Frameworks/ApplicationServices.framework/Headers/ApplicationServices.h:64:10: fatal error:
'ImageIO/ImageIO.h' file not found
#include <ImageIO/ImageIO.h>
^
1 error generated.
make: *** [main.o] Error 1
I do not know why this ImageIO/ImageIO.h is not found. What is the reason behind this?
Additionally I would like to know how to make Clang to look into the Frameworks present in /Volumes/Xcode.app/Contents/Developer/ (specified in option -F)?

It sounds like you're trying to build against the OS X 10.8 SDK from the command-line. The compiler invocation you're after will look something like so:
xcrun clang -arch x86_64 -Wall -DDEBUG=1 -g -o main.o main.m -mmacosx-version-min=10.8 -isysroot $(xcodebuild -version -sdk macosx10.8 Path)
The -isysroot argument to clang tells it to treat the given path as the root of the system with respect to the default header and framework search paths.

Related

Categories in static lib not regocnized at runtime

I am building an executable ("tool") on Linux. Using include $(GNUSTEP_MAKEFILES)/tool.make.
It's linked to a static lib that has also be build with GNUstep. The lib
contains Categories.
The executable builds fine but has errors at runtime not recognizing
methods defined in the static lib's Category:
Uncaught exception NSInvalidArgumentException, reason:
ClassNameOfClassTheCategoryExtends(instance) does not recognize
nameOfMethodInCategory
I am trying to fix that by passing -ObjC to the linker flags (also
tried -all_load) in the executable's GNUmakefile:
ADDITIONAL_LDFLAGS = -ObjC -all_load
But that seems to be ignored by clang. Here is the relevant output of
make install messages=yes debug=yes
clang: warning: argument unused during compilation: '-ObjC'
[-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-all_load'
[-Wunused-command-line-argument]
It looks like ADDITIONAL_LDFLAGS are used compiling, not linking.
Using this leads to the same result:
LDFLAGS := $(LDFLAGS) -ObjC
The excecutables GNUmakefileincludes the following:
include $(GNUSTEP_MAKEFILES)/common.make
# My make
include $(GNUSTEP_MAKEFILES)/tool.make
The resulting command line output is:
$ make install messages=yes debug=yes
This is gnustep-make 2.9.0. Type 'gmake print-gnustep-make-help' for help.
Running in gnustep-make version 2 strict mode.
Making all for tool NameOfExcecutable...
clang -ObjC -fuse-ld=/usr/bin/ld.gold -pthread -fexceptions -rdynamic -fobjc-runtime=gnustep-2.0 -fblocks -o obj/NameOfExcecutable \
./obj/NameOfExcecutable.obj/main.m.o ./obj/NameOfExcecutable.obj/MyClass.m.o ./obj/NameOfExcecutable.obj/StreamRunLoop.m.o ./obj/NameOfExcecutable.obj/Connector.m.o ./obj/NameOfExcecutable.obj/HTTPClient.m.o \
-L/home/user/GNUstep/Library/Libraries -L/usr/GNUstep/Local/Library/Libraries -L/usr/GNUstep/System/Library/Libraries -lgnustep-base -ldispatch -l/path/to/libOwnLib1.a -l/path/to/libOwnLib2.a -l/path/to/libOwnHavingTheCategories.a -l/path/to/libOwnLib4.a -l/path/to/libOwnLib5.a -luuid -lz -lpthread -ldl -lpthread -lobjc -lm
clang: warning: argument unused during compilation: '-ObjC' [-Wunused-command-line-argument]
Question:
What am I doing wrong
or
How can I work around the issue?
After digging into the issue of the linker not knowing the -ObjC flag (which we are used to use in Xcode) it looks like:
only ld.ld64 is aware of this flag
ld.ld64 is a (too genericly named) "linker for macOS" (from LLDB.org)
thus is not available for Linux linkers
To workaround we first stopped using GNUstep makefiles to
disable all GNUstep magic understand what is going on and wrote our own makefiles.
The actual fix to force link/load all .o files was to explicitly pass --whole-archive to the linker:
-Wl,-whole-archive path/to/static/lib/containing/categories/libOwnLib1.a -Wl,-no-whole-archive

How to set the deployment target when running clang with "syntax-only" option

How can I properly propagate the deployment target setting to clang
when using the -fsyntax-only option?
I'm running the clang process from the Emacs flycheck-mode in order to check the syntax
of the Objective-C code. Here is the slightly edited command line invocation:
Tue Apr 15 11:49:16 2014
clang failed with error 1:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -cc1 -fsyntax-only -x objective-c -std=gnu99 -fblocks -fobjc-arc -fno-builtin -fexceptions -fasm-blocks -Wprotocol -Wdeprecated-declarations -Wno-sign-conversion -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk -D__OBJC__ -DTARGET_IPHONE_SIMULATOR -DIBOutlet=__attribute__((iboutlet)) -DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName))) -DIBAction=void)__attribute__((ibaction) -D__IPHONE_OS_VERSION_MIN_REQUIRED=70000 -F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk/System/Library/Frameworks -F/Applications/Xcode.app/Contents/Developer/Library/Frameworks -FExampleApp -include ExampleApp/ExampleApp/ExampleApp-Prefix.pch -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk/usr/include -code-completion-at -:473:3 -
In file included from <built-in>:165:
In file included from <command line>:7:
In file included from /Users/rk/Developer/ExampleApp/src/ios/./ExampleApp/ExampleApp/ExampleApp-Prefix.pch:12:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h:9:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIAccelerometer.h:8:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:106:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSProgress.h:14:5: error: the current deployment target does not support automated __weak references
__weak id _group;
^
The problem is that obviously the deplyoment target is not set
correctly. I've tried setting the enviroment variable:
export IPHONEOS_DEPLOYMENT_TARGET=7.0
to no avail. Unfortunately, when using the -fsyntax-only option clang doesn't
accept -mios-simulator-version-min=7.0 option.
clang supports the following flags for setting the deployment target:
-mios-version-min=<value>
-mmacosx-version-min=<value>
So in your case, you probably want to find a way to pass -mios-version-min=7.0 to clang.

Objective C Library and Search Path

I created a static library in Objective C (for OSX) for performing some calculations. I then compiled it and included it in another project. Later on I'm not able to use it in my codes.
1> When I wrote
import "Auth.h"
it was giving me a File Not Found error. Why is it so?
2> Then I had to set the search path to the source of the libraries and it got compiled and executed correctly. Does that mean I can't reuse the compiled library with other projects without distributing the source code along with it?
3> I thought if Search path is being specified then the compiled library won't need to be needed. So I deleted the library. But that didn't work. It means source + the library both are required.
What is actually happenning. I just want to distribute libAuth.a with other teams for the project without giving out the source. How can I do that.
You just need to provide the library file (.a) and the header files; the source files can remain private and undistributed.
Be sure to compile the library for all architectures (x86_64 and i386 on OSX) that can possibly use the library, using lipo to create a fat binary .a file.
For example:
xcrun --sdk macosx10.8 clang -arch x86_64 -o file1.o file1.m
xcrun --sdk macosx10.8 clang -arch x86_64 -o file2.o file2.m
xcrun --sdk macosx10.8 libtool -static -arch_only x86_64 -o libmystuff_x86_64.a file1.o file2.o
xcrun --sdk macosx10.8 clang -arch i386 -o file1.o file1.m
xcrun --sdk macosx10.8 clang -arch i386 -o file2.o file2.m
xcrun --sdk macosx10.8 libtool -static -arch_only i386 -o libmystuff_i386.a file1.o file2.o
xcrun --sdk macosx10.8 lipo -arch x86_64 libmystuff_x86_64.a -arch i386 libmystuff_i386.a -create -output libmystuff.a
Try adding the followings in your main project target settings;
”-ObjC” and ”-all_load” to Build Settings > Linking > Other Linker Flags,
”$(TARGET_BUILD_DIR)/usr/local/lib/include” and ”$(OBJROOT)/UninstalledProducts/include” to Build Settings > Search Paths > Header Search Paths,
"$(BUILT_PRODUCTS_DIR)" to Build Settings > User Header Search Paths.

Compile Mach-o arm object file

Im trying to compile a mach-o arm object file to mach-o arm executable using the command line. I have used various commands like these
clang -arch armv7 helloapp.o -o helloapp
clang helloapp.o -o helloapp
gcc helloapp.o -o helloapp
They all return different errors saying compiling for wrong architecture or missing neccessary files. What is the command I need to compile this properly??
The default compilers (the ones in your $PATH) reference the ones that can compile for your local machine. You need a cross-compiler that knows how to create ARM binaries. If you've got Xcode with iOS SDK installed you can use for example:
PATH_TO_Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc
or
PATH_TO_Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
For example, on my machine:
ARM_GCC=~/Documents/Xcode4.6.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc
IOS_SDK=~/Documents/Xcode4.6.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk
# Compile
$ARM_GCC -arch armv7 -c test.c -o test.o
# Link
$ARM_GCC -arch armv7 -isysroot "$IOS_SDK" test.o -o test
If I then run file test I get:
test: Mach-O executable arm

Appcelerator module with my own sqlite3 build

I am writing an appcelerator module to use my own sqlite3 build. The problem that I am facing is that the default system sqlite code seems to get linked regardless.
I have tried a number of things, but I would have throught that placing all the sqlite code in my .m file would result in that code being called.
MySqlite.m
#import "sqlite3.h"
#import "sqlite3.c"
#pragma Public APIs
-(NSString *)getSqliteVersion:(id)args
{
return [NSString stringWithFormat:#"%s", sqlite3_libversion()];
}
The getSqliteVersion member still returns version number of the iOS standard sqlite library
So does anyone know how to alter the linker to pick up my own sqlite code or is there a way to "wrap" the sqlite in a namespace or such like?
EDIT 10/10/12:
Sorry, bit more info that is relevant. The build process is two steps.
The part I am doing is to build the module which is a packaged static library, i.e. a .a file
This .a file is distributed to other users and then they build their application with this module. So that is why I can't control the second linking step and remove any .dylib sqlite references.
Some how I think I need to get my sqlite lib into a private "namespace". I use namespace conceptually, I know C doesn't have them
Not sure if it helps, but the Ti build commands for the module build seem to be:
Build settings from command line:
SDKROOT = iphonesimulator5.0
=== BUILD NATIVE TARGET tisqlite_crypt_ios OF PROJECT tisqlite_crypt_ios WITH CONFIGURATION Release ===
Check dependencies
CompileC build/tisqlite_crypt_ios.build/Release-iphonesimulator/tisqlite_crypt_ios.build/Objects-normal/i386/UkCoClinicalsoftwaresolutionsTisqlite_crypt_iosModule.o Classes/UkCoClinicalsoftwaresolutionsTisqlite_crypt_iosModule.m normal i386 objective-c com.apple.compilers.llvm.clang.1_0.compiler
cd /TitaniumStudioWorkspace/tisqlite_crypt_ios
setenv LANG en_US.US-ASCII
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/opt/local/bin:/usr/local/git/bin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/clang -x objective-c -arch i386 -fmessage-length=0 -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -std=c99 -Wno-trigraphs -fpascal-strings -Os -Wno-return-type -Wno-parentheses -Wswitch -Wunused-function -Wno-unused-parameter -Wno-unused-variable -Wno-unused-value -Wno-shorten-64-to-32 -DTI_VERSION= -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -fexceptions -fasm-blocks -mmacosx-version-min=10.6 -gdwarf-2 -Wno-sign-conversion -fobjc-abi-version=2 -fobjc-legacy-dispatch "-DIBOutlet=__attribute__((iboutlet))" "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" "-DIBAction=void)__attribute__((ibaction)" -D__IPHONE_OS_VERSION_MIN_REQUIRED=40000 -iquote /TitaniumStudioWorkspace/tisqlite_crypt_ios/build/tisqlite_crypt_ios.build/Release-iphonesimulator/tisqlite_crypt_ios.build/UkCoClinicalsoftwaresolutionsTisqlite_crypt_ios-generated-files.hmap -I/TitaniumStudioWorkspace/tisqlite_crypt_ios/build/tisqlite_crypt_ios.build/Release-iphonesimulator/tisqlite_crypt_ios.build/UkCoClinicalsoftwaresolutionsTisqlite_crypt_ios-own-target-headers.hmap -I/TitaniumStudioWorkspace/tisqlite_crypt_ios/build/tisqlite_crypt_ios.build/Release-iphonesimulator/tisqlite_crypt_ios.build/UkCoClinicalsoftwaresolutionsTisqlite_crypt_ios-all-target-headers.hmap -iquote /TitaniumStudioWorkspace/tisqlite_crypt_ios/build/tisqlite_crypt_ios.build/Release-iphonesimulator/tisqlite_crypt_ios.build/UkCoClinicalsoftwaresolutionsTisqlite_crypt_ios-project-headers.hmap -I/TitaniumStudioWorkspace/tisqlite_crypt_ios/build/Release-iphonesimulator/include "-I/Library/Application Support/Titanium/mobilesdk/osx/2.1.3.GA/iphone/include" "-I/Library/Application Support/Titanium/mobilesdk/osx/2.1.3.GA/iphone/include/TiCore" -I/TitaniumStudioWorkspace/tisqlite_crypt_ios/build/tisqlite_crypt_ios.build/Release-iphonesimulator/tisqlite_crypt_ios.build/DerivedSources/i386 -I/TitaniumStudioWorkspace/tisqlite_crypt_ios/build/tisqlite_crypt_ios.build/Release-iphonesimulator/tisqlite_crypt_ios.build/DerivedSources -F/TitaniumStudioWorkspace/tisqlite_crypt_ios/build/Release-iphonesimulator -DTI_POST_1_2 -include /var/folders/LP/LPsQmql2FfCGO9YCrCUKUU+++TI/-Caches-/com.apple.Xcode.501/SharedPrecompiledHeaders/UkCoClinicalsoftwaresolutionsTisqlite_crypt_ios_Prefix-hbaweqhgijjnfpfynapljpziqmjk/UkCoClinicalsoftwaresolutionsTisqlite_crypt_ios_Prefix.pch -MMD -MT dependencies -MF /TitaniumStudioWorkspace/tisqlite_crypt_ios/build/tisqlite_crypt_ios.build/Release-iphonesimulator/tisqlite_crypt_ios.build/Objects-normal/i386/UkCoClinicalsoftwaresolutionsTisqlite_crypt_iosModule.d -c /TitaniumStudioWorkspace/tisqlite_crypt_ios/Classes/UkCoClinicalsoftwaresolutionsTisqlite_crypt_iosModule.m -o /TitaniumStudioWorkspace/tisqlite_crypt_ios/build/tisqlite_crypt_ios.build/Release-iphonesimulator/tisqlite_crypt_ios.build/Objects-normal/i386/UkCoClinicalsoftwaresolutionsTisqlite_crypt_iosModule.o
In file included from /TitaniumStudioWorkspace/tisqlite_crypt_ios/Classes/UkCoClinicalsoftwaresolutionsTisqlite_crypt_iosModule.m:14:
/TitaniumStudioWorkspace/tisqlite_crypt_ios/Classes/sqlite3.c:27620:32:{27620:32-27620:45}{27620:30-27620:31}: warning: implicit conversion from 'long long' to 'long' changes value from 9223372036854775807 to -1 [-Wconstant-conversion,3]
mask = (sizeof(long)==8) ? LARGEST_INT64 : 0x7fffffff;
~ ^~~~~~~~~~~~~
/TitaniumStudioWorkspace/tisqlite_crypt_ios/Classes/sqlite3.c:7946:25: note: instantiated from:
#define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
Libtool build/Release-iphonesimulator/libUkCoClinicalsoftwaresolutionsTisqlite_crypt_ios.a normal i386
cd /TitaniumStudioWorkspace/tisqlite_crypt_ios
setenv MACOSX_DEPLOYMENT_TARGET 10.6
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/opt/local/bin:/usr/local/git/bin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/libtool -static -arch_only i386 -syslibroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -L/TitaniumStudioWorkspace/tisqlite_crypt_ios/build/Release-iphonesimulator -filelist /TitaniumStudioWorkspace/tisqlite_crypt_ios/build/tisqlite_crypt_ios.build/Release-iphonesimulator/tisqlite_crypt_ios.build/Objects-normal/i386/UkCoClinicalsoftwaresolutionsTisqlite_crypt_ios.LinkFileList -ObjC -framework Foundation -o /TitaniumStudioWorkspace/tisqlite_crypt_ios/build/Release-iphonesimulator/libUkCoClinicalsoftwaresolutionsTisqlite_crypt_ios.a
** BUILD SUCCEEDED **