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
Related
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.
I have a third party iOS library that links and runs fine in my app and in the simulator. I am trying to extract the object files from it in order to integrate it with another piece of third party software that repackages the object files with their own code. However, I am unable to extract the object files via ar; I consistently get the error, "Inappropriate file type or format".
The library in question is a fat library with armv7, armv7s, and i386 included. Stock lipo doesn't know about armv7s on my machine, but Xcode's does:
$ lipo -info library.a
Architectures in the fat file: library.a are: armv7 (cputype (12) cpusubtype (11)) i386
$ xcrun -sdk iphoneos lipo -info library.a
Architectures in the fat file: library.a are: armv7 armv7s i386
I can successfully thin it out with lipo:
$ xcrun -sdk iphoneos lipo library.a -thin armv7 -output library-armv7.a
$ xcrun -sdk iphoneos lipo -info library-armv7.a
Non-fat file: library-armv7.a is architecture: armv7
However, even after thinning it out, I can't manipulate it with ar:
$ xcrun -sdk iphoneos ar -tv library-armv7.a
ar: library-armv7.a: Inappropriate file type or format
$ xcrun -sdk iphoneos ar -xv library-armv7.a
ar: library-armv7.a: Inappropriate file type or format
I'm on OS X 10.8.2, Xcode 4.6 with development tools installed.
Is there any additional step I can take for this troublesome library?
Update in response to Martin's comment
file shows the following:
$ file library.a
library.a: Mach-O universal binary with 3 architectures
library.a (for architecture armv7): Mach-O object arm
library.a (for architecture cputype (12) cpusubtype (11)): Mach-O object arm
library.a (for architecture i386): Mach-O object i386
$ file library-armv7.a
library-armv7.a: Mach-O object arm
Looks like it's not a library at all!
The "library" is not actually a library, but is an object file itself. There is nothing further to extract.
This script works well. Try it.
https://code.google.com/p/ompt-intel-openmp/source/browse/itt/libomp_oss/tools/extract-objects.pl
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.
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 **
I have 3 apps written in Obj-C that I want to modify and convert to libraries, so I can use them in a Monotouch app.
Where do I find docs that tell me how to take Obj-C code and turn it into libraries?
Imagine you have a file called lib1.m
You will first have to compile it as object code. For instance:
gcc -Wall -framework Cocoa -o lib1.o lib1.m
That will create lib1.o
Then you'll have to decide wether you want a static or dynamic library.
To build a static library, you'll need a library object first:
glibtool --quiet --mode=compile gcc -o lib1.lo -c lib1.c
Then you can create the static library from the library archive:
glibtool --quiet --mode=link gcc -o lib1.la -c lib1.lo
To build a dynamic library:
libtool -dynamic -flat_namespace -lSystem -undefined suppress -macosx_version_min 10.6 -install_name /usr/local/lib/lib1.dylib -o lib1.dylib lib1.o
Note that for dynamic libraries, you must provide the install path when creating the library.