Check iOS deployment target of a static library - ios

I have many static libs like libBlah.a
With file tool I can check supported architectures. (arm64 or i386)
Is there tool to check iOS Deployment Target of the static lib?

You can use otool to inspect the library file. With some experimentation I found that the flags -lv gave me useful output. Open up a terminal window and switch to the directory your library is in:
cd /path/to/parent/directory
(Hint: you can drag the icon from the title bar of a finder window into the terminal and it will enter the path for you). Then type the following command:
otool -lv myStaticLibrary.a | less
In less, type / (search) and then LC_VERSION_MIN_IPHONEOS. You should see something like this:
Load command 1
cmd LC_VERSION_MIN_IPHONEOS
cmdsize 16
version 7.0
sdk n/a
The deployment target should be the value next to version.

The target OS version is encoded in the LC_VERSION_MIN_IPHONEOS load command in the MachO header of the static library. You can see it via:
otool -l mylib.a | grep -A 3 LC_VERSION
Example output:
cmd LC_VERSION_MIN_IPHONEOS
cmdsize 16
version 9.0
sdk n/a

have you tried using preprocess macros?
#if IPHONEOS_DEPLOYMENT_TARGET (iOS Deployment Target)

Related

Clang showing compiler error with fuzzer argument

I am trying to experiment with libFuzzer library and going through the toy-example[1].
keep-learnings-MacBook-Pro:Ccodeanalysis keep_learning$ cat Fuzzme.cpp
#include <stdint.h>
#include <stddef.h>
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if (size > 0 && data[0] == 'H')
if (size > 1 && data[1] == 'I')
if (size > 2 && data[2] == '!')
__builtin_trap();
return 0;
}
keep-learnings-MacBook-Pro:Ccodeanalysis keep_learning$ clang++ -fsanitize=address,fuzzer Fuzzme.cpp
ld: file not found: /Library/Developer/CommandLineTools/usr/lib/clang/10.0.1/lib/darwin/libclang_rt.fuzzer_osx.a
clang: error: linker command failed with exit code 1 (use -v to see invocation)
keep-learnings-MacBook-Pro:Ccodeanalysis keep_learning$ clang++ --version
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
A quick Google search showed me this [2], but other than that I could not find any meaningful information to resolve it, hence posting here. Could some one please tell me how to solve this ? Thanks in advance.
[1] http://llvm.org/docs/LibFuzzer.html#toy-example
[2] https://bugs.llvm.org/show_bug.cgi?id=39794
As you have noticed, there is no fuzzer runtime shipped with Apple developer tools. So you'd either report this issue to Apple folks, or build the runtime library by yourself from the sources (or both).
As Anton stated, Apple Developer Tools do not include the fuzzer library, leaving you to compile from source, or asking Apple.
It turns out LLVM also hosts pre-compiled binaries for some releases on their downloads page:
https://releases.llvm.org/download.html.
On that page, find your LLVM version (eg "Download LLVM 10.0.0"), and go a bit further until you see Pre-Built Binaries. Don't see binaries for your LLVM version? Pick the nearest lower version. The OP and I both have clang++ 10.0.1, so we'd pick 10.0.0.
Click the macOS link to download, pop into the Terminal to untar and copy the libraries, and you're done. I did it with a few environment variables (those paths are killer!), and a cp -n to preserve existing files.
export CLANG_ROOT=clang+llvm-10.0.0-x86_64-apple-darwin/lib/clang/10.0.0
export XCODE_ROOT=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.1
tar xvf clang+llvm-10.0.0-x86_64-apple-darwin.tar.xz $CLANG_ROOT/include/fuzzer $CLANG_ROOT/lib/darwin
sudo cp -rn $CLANG_ROOT/include/fuzzer $XCODE_ROOT/include
sudo cp -n $CLANG_ROOT/lib/darwin/* $XCODE_ROOT/lib/darwin
I did exactly the above, and my code compiled and linked right away.

Export all localizations on the command line in Xcode

I have 26 languages successfully localized and tested. I am able to successfully export all 26 localizations with option: "Editor" -> "Export for Localization...", then selecting all of them.
However, when I use the following xcodebuild command, it exports my default language "en", and nothing else.
xcodebuild -exportLocalizations -localizationPath TempLocalizationExport
How do I export all twenty-six Localizations rather than just "en"?
There are no command line errors outputted from the command.
I've seached everywhere for official xcodebuild commandline command documentation on developer.apple.com, and I can't find a verbose and helpful source that addresses additional -exportLocalizations options and standard behavior.
According to the docs:
To export localizations, enter this command in Terminal, replacing the
dirpath and projectname arguments:
xcodebuild -exportLocalizations -localizationPath <dirpath> -project <projectname> [[-exportLanguage <targetlanguage>]]
The exported XLIFF files are placed in dirpath. Optionally, use the
exportLanguage argument to export other localizations.
UPDATE:
The OP discovered that multiple languages can be exported by repeating the -exportLanguage argument. For example, this command exports two languages:
xcodebuild -exportLocalizations -localizationPath TempLocalizationExport -exportLanguage es -exportLanguage ru
Seems xcodebuild doesn't support auto export all localizations at this time.
But we can do it through Xcode interface.
Also it's possible auto select all localizations with a script. Read knownRegions section in project.pbxproj, loop to argument format.

Qt-creator examples fail to build for iphonesimulator

I've successfully installed Qt 5.7.0 and Qt-creator 4.1.0 on El Capitan with Xcode 8.
I fixed the xcode sdk-version errors from qt, and now I'm trying to build one of the examples for iphonesimulator. None of them work. All of them fail with error message of type:
The following build commands failed:
CopyPNGFile Debug-iphonesimulator/2dpainting.app/Default-568h#2x.png 2dpainting.xcodeproj/Default-568h#2x.png
I can confirm that directory Debug-iphonesimulator/2dpainting.app does not have the png-file, it's actually located somewhere within the qt installation directories. Copying the png to the source folder does not help as the folder gets overwritten upon running 'make'.
Any advice would be appreciated.
Edit:
The build kit warns about the following issue:
"Device type is not supported by the Qt version". Device type is 'iOS simulator'.
I had the same problem after I had updated my Xcode to version 8.0.
My first error was "Project ERROR: Xcode not set up properly. You may need to confirm the license agreement by running /usr/bin/xcodebuild."
To solve this problem, I created a symbolic link:
cd /Applications/Xcode.app/Contents/Developer/usr/bin/
sudo ln -s xcodebuild xcrun
Then I got error "Project ERROR: Current iphonesimulator SDK version (10.0) is too old. Please upgrade Xcode."
I commented two strings out in file QT_DIR/5.7/ios/mkspecs/macx-ios-clang/features/sdk.prf
lessThan(QMAKE_MAC_SDK_VERSION, "8.0"): \
error("Current $$QMAKE_MAC_SDK SDK version ($$QMAKE_MAC_SDK_VERSION) is too old. Please upgrade Xcode.")
Then I got error about emulator. Qt could not find it. I replaced line of code in file QT_DIR/5.7/ios/mkspecs/macx-ios-clang/xcodebuild.mk from:
IPHONESIMULATOR_GENERIC_DESTINATION := "id=$(shell xcrun simctl list devices | grep -E 'iPhone|iPad' | grep -v unavailable | perl -lne 'print $$1 if /((.*?))/' | tail -n 1)"
to:
IPHONESIMULATOR_GENERIC_DESTINATION := "id=$(shell xcrun simctl list devices | grep -E 'iPhone|iPad' | grep -v unavailable | awk 'match ($$0, /\(([A-F0-9\-]*\))/ ) { print substr ($$0, RSTART+1, RLENGTH-2) }' | tail -n 1)"
And finally afer all of it I got error "The following build commands failed:
CopyPNGFile Debug-iphonesimulator/Test01.app/Default-568h#2x.png Test01.xcodeproj/Default-568h#2x.png"
This error occurred due to the fact that the system has two file xcrun. And script /Applications/Xcode.app/Contents/Developer/usr/bin/copypng starts one, which is a symbolic link. Then I changed path in this script
from:
my $PNGCRUSH = `xcrun -f pngcrush`;
to:
my $PNGCRUSH = `/usr/bin/xcrun -f pngcrush`;
And then I finally had built the project without errors and opened it in Xcode.
I had this stupid error and spent two days to nail down. I was about to downgrade Xcode and thought lets try one more time. Finally nailed down.
Symptom:
The simplest project wont build from Qt Creator. The error I would get: CopyPNG failed or something along the line and a hint '-f' unknown parameter.
Reason: xcrun takes both -f and -find from the terminal I can see, but it does not like -f from the script copypng. (copypng is a perl script by the way.)
The solution: Open the file /Applications/Xcode.app/Contents/Developer/usr/bin/copypng and find
my $PNGCRUSH = `xcrun -f pngcrush`;
changed to
my $PNGCRUSH = `xcrun -find pngcrush`;
PS: I dint have path problem with xcrun, if you have it'd be good to put the whole path as advised above.

xcodebuild target name with Umlaut

I am trying to build an iOS App using Jenkins via the xcodebuild command.
The problem is that xcodebuild does not detect the target with the German Umlaut ü.
$ /usr/bin/xcodebuild -target AppNameWithUmlautü -configuration Debug clean build
gives me following error:
xcodebuild: error: The project 'AppNameWithUmlautü.xcodeproj' does not contain a target named 'AppNameWithUmlautü'.
I checked the existence of the target using following command:
xcodebuild -list
Information about project "AppNameWithUmlautü":
Targets:
AppNameWithUmlautü
AppNameWithOutUmlaut
Build Configurations:
Debug
Release
Ad Hoc
If no build configuration is specified and -scheme is not passed then "Release" is used. This project contains no schemes.
The target without Umlaut works.
Xcode uses the "decomposite" UTF-8 representation for Umlauts in the target name: "ü" is represented as 75 CC 88. 75 is "u", and CC 88 is the UTF-8 sequence for the "COMBINING DIAERESIS".
The shell, on the other hand, uses the "composite" UTF-8 representation C3 BC for "ü".
So the target that you give on the command line does not match the target name in the Xcode project (and one could argue that this is a bug in Xcode).
I have no knowledge about Jenkins, but if you somehow can use the output of the xcodebuild -list command to get the decomposite UTF-8 target name and copy that into your Makefile, shell script or whatever you have, then this should help.

xcodebuild command with absolute path to SDK

I am using xcodebuild command line tool to build iOS app.
After instaling Xcode45-DP1 it is automatically using 6.0 SDK from the new Xcode45-DP1 app bundle for building applications. There are 2 issues when submitting this app to AppStore.
The app is now automatically built with latest SDK (6.0), which is note yet supported, so app cannot be submitted.
SOLUTION: I copied the old-current SDK (5.1) to Xcode45-DP.app and in command line specified -sdk iphoneos5.1
Second problem is that when ApplicationLoader is verifying app, is sees that SDK is used from unsupported version of Xcode (45-DP1) and rejects to upload app.
SOLUTION: I would like to specify absolute path for SDK, like: xcodebuild -sdk /path/to/5.1sdk...
The problem is that xcodebuild always says that SDK "/path/to/iPhoneOS5.1.sdk/" cannot be located.
Does anyone have an experience with how to use absolute path to sdk and what file/directory should it point to?
Thanks in advance.
I have been searching for this for a while as well and there does not appear to be a direct way of getting the full absolute path to a specific SDK. However, if you set the -sdk switch and -find-library for an arbitrary library and strip the last few path parts off you can get the full sdk path like so:
[ 13:02 jon#MacBookPro ~ ]$ export SYS_ROOT=`xcodebuild -sdk iphoneos6.0 -find-library system`
[ 13:02 jon#MacBookPro ~ ]$ echo "${SYS_ROOT/\/usr\/lib\/libsystem.dylib/}"
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk
[ 13:02 jon#MacBookPro ~ ]$ export SYS_ROOT=`xcodebuild -sdk iphonesimulator6.0 -find-library system`
[ 13:02 jon#MacBookPro ~ ]$ echo "${SYS_ROOT/\/usr\/lib\/libsystem.dylib/}"
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk

Resources