How to build dylib in XCode? - xcode

I have a library in source code, it builds in .a static library, but i need .dylib. So, i choose Mach-O-Type in "Build Settings" as "Dynamic Library", but get error:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static -arch_only x86_64 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -L/Users/abc/Library/Developer/Xcode/DerivedData/mylib-fwducbhnvcuzuzaopjfimtlylztm/Build/Products/Debug -filelist /Users/abc/Library/Developer/Xcode/DerivedData/mylib-fwducbhnvcuzuzaopjfimtlylztm/Build/Intermediates/mylib.build/Debug/mylib-osx.build/Objects-normal/x86_64/mylib-osx.LinkFileList -fobjc-link-runtime -framework Foundation -o /Users/abc/Library/Developer/Xcode/DerivedData/mylib-fwducbhnvcuzuzaopjfimtlylztm/Build/Products/Debug/libmylib-osx.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: unknown option character `f' in: -fobjc-link-runtime
libtool for some reason uses "-static" instead "-dynamic" flag... Compatibility version i've set. What do you think could be wrong?

object files (.o) could be extracted from archive file (.a) and then packed in .dylib with libtool or gcc

Related

Xcode 9 - No option to create dylib project iOS

I remember in old Xcode there was option under Create New Project there was option to create BSD Dynamic Library - dylib. However now I see only Cocoa Framework, Static Library and Metal Library.
Any hints?
You may create a project for an iOS static lib, and create a dynamic lib from the static one with a custom build phase with the following command:
xcrun --sdk iphoneos clang -arch <ARCH> -shared -all_load \
-o lib<NAME>.dylib lib<NAME>.a
where <ARCH> is either armv7 or arm64 and <NAME>is the base name of your lib. You may check or list the architectures with file command. E.g.:
file <path>/lib<NAME>.a`
lib<NAME>.a (for architecture armv7): current ar archive random library
lib<NAME>.a (for architecture arm64): current ar archive random library
If more than one architecture is listed, Xcode has produced a universal static library. In this case you may create a universal shared library with multiple -arch flags:
xcrun --sdk iphoneos clang -arch armv7 -arch arm64 -shared -all_load \
-o lib<NAME>.dylib lib<NAME>.a
You may need to specify additional linker flags (e.g. -l for linking non-standard libs).

archiving in xcode 7.3.1

i am trying to get my app on testflight for testing. however when following the instruction on this video https://www.youtube.com/watch?v=6tydk4Fc-tg&t=302s everything work up to trying to archive the app.
i get the below error and i'm not quite sure what to do. if you have any idea on how to solve this problem, please help. i'm using Xcode 7.3.1 and ivy 1.9.1.
ld: warning: directory not found for option
'-L/Users/nabi/Desktop/kivy-ios/break-ios/../build/lib'
ld: warning: directory not found for option
'-F/Users/nabi/Desktop/kivy-ios/dist/frameworks'
ld: '/Users/nabi/Desktop/kivy-ios/dist/lib/libfreetype.a(ftsystem.o)'
does not contain bitcode. You must rebuild it with bitcode enabled
(Xcode setting ENABLE_BITCODE), obtain an updated library from the
vendor, or disable bitcode for this target. for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
Ld
/Users/nabi/Library/Developer/Xcode/DerivedData/break-bnyieydgxnbwarhabzewbmeqxnyr/Build/Intermediates/ArchiveIntermediates/break/IntermediateBuildFilesPath/break.build/Release-iphoneos/break.build/Objects-normal/arm64/break
normal arm64
cd /Users/nabi/Desktop/kivy-ios/break-ios
export IPHONEOS_DEPLOYMENT_TARGET=8.1
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk
-L/Users/nabi/Library/Developer/Xcode/DerivedData/break-bnyieydgxnbwarhabzewbmeqxnyr/Build/Intermediates/ArchiveIntermediates/break/BuildProductsPath/Release-iphoneos
-L/Users/nabi/Desktop/kivy-ios/break-ios/../dist/lib -L/Users/nabi/Desktop/kivy-ios/break-ios/../build/lib -F/Users/nabi/Library/Developer/Xcode/DerivedData/break-bnyieydgxnbwarhabzewbmeqxnyr/Build/Intermediates/ArchiveIntermediates/break/BuildProductsPath/Release-iphoneos
-F/Users/nabi/Desktop/kivy-ios/dist/frameworks -filelist /Users/nabi/Library/Developer/Xcode/DerivedData/break-bnyieydgxnbwarhabzewbmeqxnyr/Build/Intermediates/ArchiveIntermediates/break/IntermediateBuildFilesPath/break.build/Release-iphoneos/break.build/Objects-normal/arm64/break.LinkFileList
-miphoneos-version-min=8.1 -fembed-bitcode -Xlinker -bitcode_verify -Xlinker -bitcode_hide_symbols -Xlinker -bitcode_symbol_map -Xlinker /Users/nabi/Library/Developer/Xcode/DerivedData/break-bnyieydgxnbwarhabzewbmeqxnyr/Build/Intermediates/ArchiveIntermediates/break/BuildProductsPath/Release-iphoneos
-all_load -fobjc-link-runtime -framework AudioToolbox -framework ImageIO -framework MessageUI -framework UIKit -framework OpenGLES
-framework CoreMotion -framework MobileCoreServices -framework CoreGraphics -framework Accelerate -framework QuartzCore -lc++ -lz
-lsqlite3 -lbz2 -lfreetype -lsdl2_mixer -lsdl2 -lsdl2_image -lffi -lkivy -lpython -lios -lsdl2_ttf -Xlinker -dependency_info -Xlinker /Users/nabi/Library/Developer/Xcode/DerivedData/break-bnyieydgxnbwarhabzewbmeqxnyr/Build/Intermediates/ArchiveIntermediates/break/IntermediateBuildFilesPath/break.build/Release-iphoneos/break.build/Objects-normal/arm64/break_dependency_info.dat
-o /Users/nabi/Library/Developer/Xcode/DerivedData/break-bnyieydgxnbwarhabzewbmeqxnyr/Build/Intermediates/ArchiveIntermediates/break/IntermediateBuildFilesPath/break.build/Release-iphoneos/break.build/Objects-normal/arm64/break
ld: warning: directory not found for option
'-L/Users/nabi/Desktop/kivy-ios/break-ios/../build/lib' ld: warning:
directory not found for option
'-F/Users/nabi/Desktop/kivy-ios/dist/frameworks' ld:
'/Users/nabi/Desktop/kivy-ios/dist/lib/libfreetype.a(ftsystem.o)' does
not contain bitcode. You must rebuild it with bitcode enabled (Xcode
setting ENABLE_BITCODE), obtain an updated library from the vendor, or
disable bitcode for this target. for architecture arm64 clang: error:
linker command failed with exit code 1 (use -v to see invocation)
The error tells you clearly what to do. When you see the dialog that asks if you want to rebuild using bitcode, you must uncheck that option. If you are not even getting that far, use the build settings of your target to disable bitcode:
In that screen shot, you'd need to switch from Yes to No.

Debugging linker error with Xcode - sdl static library

I am trying to follow this guide here for building SDL2 for iOS:
http://lazyfoo.net/tutorials/SDL/52_hello_mobile/ios_mac/index.php
I am able to build the libSDL2.a static library, however I am getting a linker error when I attempt to build his example hello world application which uses it.
Ld /Users/testuser/Library/Developer/Xcode/DerivedData/___PROJECTNAME___-egvszvnfjpicgqdtaazpczjuebut/Build/Products/Debug-iphonesimulator/___PROJECTNAME___.app/___PROJECTNAME___ normal x86_64
cd "/Users/testuser/Documents/iosBuild/SDL iOS Application"
export IPHONEOS_DEPLOYMENT_TARGET=10.0
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.0.sdk -L/Users/testuser/Library/Developer/Xcode/DerivedData/___PROJECTNAME___-egvszvnfjpicgqdtaazpczjuebut/Build/Products/Debug-iphonesimulator -F/Users/testuser/Library/Developer/Xcode/DerivedData/___PROJECTNAME___-egvszvnfjpicgqdtaazpczjuebut/Build/Products/Debug-iphonesimulator -filelist /Users/testuser/Library/Developer/Xcode/DerivedData/___PROJECTNAME___-egvszvnfjpicgqdtaazpczjuebut/Build/Intermediates/___PROJECTNAME___.build/Debug-iphonesimulator/___PROJECTNAME___.build/Objects-normal/x86_64/___PROJECTNAME___.LinkFileList -mios-simulator-version-min=10.0 -Xlinker -object_path_lto -Xlinker /Users/testuser/Library/Developer/Xcode/DerivedData/___PROJECTNAME___-egvszvnfjpicgqdtaazpczjuebut/Build/Intermediates/___PROJECTNAME___.build/Debug-iphonesimulator/___PROJECTNAME___.build/Objects-normal/x86_64/___PROJECTNAME____lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -lSDL2 -framework GameController -framework Foundation -framework UIKit -framework OpenGLES -framework QuartzCore -framework CoreAudio -framework AudioToolbox -framework CoreGraphics -framework CoreMotion -Xlinker -dependency_info -Xlinker /Users/testuser/Library/Developer/Xcode/DerivedData/___PROJECTNAME___-egvszvnfjpicgqdtaazpczjuebut/Build/Intermediates/___PROJECTNAME___.build/Debug-iphonesimulator/___PROJECTNAME___.build/Objects-normal/x86_64/___PROJECTNAME____dependency_info.dat -o /Users/testuser/Library/Developer/Xcode/DerivedData/___PROJECTNAME___-egvszvnfjpicgqdtaazpczjuebut/Build/Products/Debug-iphonesimulator/___PROJECTNAME___.app/___PROJECTNAME___
ld: library not found for -lSDL2
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Per his instructions, I copied the project template and added the libSDL2.a lib that I built under the Build Phases -> link binary with libraries menu:
Any suggestions for how I can debug this problem?
Edit: My build target configuration in the project which uses the library:
try to build your library with this script. the final product will be placed in your home ~/SDL directory.
#!/bin/sh
PREFIX=$HOME/SDL
SYMROOT="SYMROOT=$PREFIX/release"
SDK_DEVICE="-sdk iphoneos"
SDK_SIMULATOR="-sdk iphonesimulator"
CONF_DEBUG="-configuration Debug"
CONF_RELEASE="-configuration Release"
mkdir -p $PREFIX
cd $PREFIX
wget https://www.libsdl.org/release/SDL2-2.0.4.zip
unzip SDL2-2.0.4.zip
rm -f SDL2-2.0.4.zip
# ------------------------------------------------------------------------
# SDL
# ------------------------------------------------------------------------
cd $PREFIX/SDL2-2.0.4/Xcode-iOS/SDL
SCHEME="libSDL"
PROJ="-project SDL.xcodeproj"
#xcodebuild OTHER_CFLAGS="-fembed-bitcode" OTHER_LDFLAGS="-lobjc" ONLY_ACTIVE_ARCH=NO -arch i386 -arch x86_64 $PROJ $SDK_SIMULATOR $CONF_DEBUG -scheme='$SCHEME' build $SYMROOT
xcodebuild OTHER_CFLAGS="-fembed-bitcode" ONLY_ACTIVE_ARCH=NO -arch i386 -arch x86_64 $PROJ $SDK_SIMULATOR $CONF_RELEASE -scheme='$SCHEME' build $SYMROOT
#xcodebuild OTHER_CFLAGS="-fembed-bitcode" OTHER_LDFLAGS="-lobjc" ONLY_ACTIVE_ARCH=NO -arch arm64 -arch armv7 $PROJ $SDK_DEVICE $CONF_DEBUG -scheme='$SCHEME' build $SYMROOT
xcodebuild OTHER_CFLAGS="-fembed-bitcode" ONLY_ACTIVE_ARCH=NO -arch arm64 -arch armv7 $PROJ $SDK_DEVICE $CONF_RELEASE -scheme='$SCHEME' build $SYMROOT
lipo $PREFIX/release/Release-iphonesimulator/libSDL2.a $PREFIX/release/Release-iphoneos/libSDL2.a -create -output $PREFIX/libSDL2.a
It's likely that the static library you built does not contain the architecture for which you're building your application. You'll need to build a static library that contains the architectures for the platform you want to build.
Also, keep in mind that it's not actually supported to put architectures for different platforms (such as iOS and tvOS, or even iOS and iOS Simulator—the simulators are separate platforms) in a single binary. You'll need a separate library or framework for each platform you're targeting, though each one can of course contain slices for all of that platform's supported architectures.

Set include directory for linker (ld) on OSX

I have a problem with linking a compiled program (see github repo for details).
The osx specific makefile section is here:
CFLAGS = -v -arch x86_64 -Wall -fPIC -O2 -I./include $(OPTS)
LDFLAGS = -v -arch x86_64 -lpthread /usr/local/lib/libportaudio.a -framework CoreAudio -framework AudioToolbox -framework AudioUnit -framework Carbon
EXECUTABLE ?= squeezelite-osx
include Makefile
The compilation works fine, but during the linking it fails with:
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.2.0
Thread model: posix
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.11.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -o squeezelite-osx main.o slimproto.o buffer.o stream.o utils.o output.o output_alsa.o output_pa.o output_stdout.o output_pack.o decode.o flac.o pcm.o mad.o vorbis.o faad.o mpg.o dsd.o dop.o dsd2pcm/dsd2pcm.o process.o resample.o -lpthread /usr/local/lib/libportaudio.a -framework CoreAudio -framework AudioToolbox -framework AudioUnit -framework Carbon -lFLAC -lmad -lvorbisfile -lfaad -lmpg123 -lsoxr -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.2/lib/darwin/libclang_rt.osx.a
ld: library not found for -lFLAC
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [squeezelite-osx] Error 1
The library which is not found is in the folder /usr/local/include and I think I have to add this path to the include path of the linker.
How can I add the path /usr/local/include to the include path of the linker?
The linker doesn't use include files; that's the compiler (actually the pre-processor, but let's keep it simple).
Instead you need to tell the linker that it should look in /usr/local/lib using the -L option:
-L/usr/local/lib
Note: you can provide more than one -L option to the linker.

Xcode libtool error on OpenTrack build

I have used CMake 3.3.0-rc4 to generate an Xcode project for OpenTrack. However, when I attempt to build the ALL_BUILD target in Xcode 6.4, I immediately get the error below.
Libtool build/Debug/libopentrack-version.a normal x86_64
cd /Users/david/Documents/Programming/OpenTrack
export MACOSX_DEPLOYMENT_TARGET=10.10
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static -arch_only x86_64 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -L/Users/user/Documents/Programming/OpenTrack/build/Debug -filelist /Users/user/Documents/Programming/OpenTrack/build/opentrack.build/Debug/opentrack-version.build/Objects-normal/x86_64/opentrack-version.LinkFileList -stdlib=libc++ -framework Cocoa -framework CoreFoundation -lobjc -lz -framework Carbon -o /Users/user/Documents/Programming/OpenTrack/build/Debug/libopentrack-version.a
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: unknown option character `t' in: -stdlib=libc++
Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-sacLT] [-no_warning_for_no_symbols]
Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -dynamic [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-o output] [-install_name name] [-compatibility_version #] [-current_version #] [-seg1addr 0x#] [-segs_read_only_addr 0x#] [-segs_read_write_addr 0x#] [-seg_addr_table <filename>] [-seg_addr_table_filename <file_system_path>] [-all_load] [-noall_load]
The Build Settings for the project has the following set for Linking / Other Librarian Flags:
OTHER_LIBTOOLFLAGS = -stdlib=libc++ -framework Cocoa -framework CoreFoundation -lobjc -lz -framework Carbon
From the libtool usage statement above, it looks to me like this set of options was generated for an entirely different version of libtool. What can I do (if anything) to get this project to build with the current version of Xcode?
You cannot use the flag -stdlib=libc++ or -framework with libtool, as they are valid only in the linker, so you should make OTHER_LIBTOOLFLAGS empty as none of those options apply

Resources