Recursively apply -arch option to all dependencies of a Xcode project - xcode

I have a script that build a list of Xcode projects using xcodebuild command line tool. After introduction of universal builds we introduced standard arch's in our xcconfig files and build settings of Xcode projects. Now I want to add an option to build only given arch's. For this I added option -arch . This works well for projects that I build using the list. Problem happens when the system tries to build dependent projects internally and since there the arch is set to universal it fails to build since its dependencies are now either intel only of arm64 only. Is there some argument I can give to xcodebuild to apply -arch option to all its dependencies as well.

Related

Generate a universal binary Xcode project to include two sets of pre-compiled libraries

I am trying to build Blender as a universal binary. Blender has a lot of libraries that can be downloaded completely pre-compiled from their subversion servers. They have one set for x86 and one set for arm64. Blender docs instruct me to run cmake . -B ../build_xcode/ -G "Xcode" which generated a Blender.xcodeproj file and other build files. I noticed that cmake is only picking up the arm64 dependencies, however which might explain why my buils keep failing 90% of the way through. I can build both arm64 and x86_64 builds separately, but not combined. Is there a way to generate this Xcode project to contain both x86 and arm64 dependencies into the same project? I have selected "Standard Architectures" in my build settings so I can confirm it is indeed configured to build a universal binary.
I have checked other posts on this website and most are for PPC/Intel days or are not relevant to my specific issue.

Xcode 10 static library doesn't include x86_64 arch

I am building a static library to be used with another project I'm working on, and eventually it will be included in a framework I'm developing. When I bring the library into my project, the arm builds work fine, but the simulator builds fail with missing symbols for the x86_64 build. I have set the build architectures in the library to
arm64 arm64e armv7 armv7s x86_64
I have tried various settings, like $(ARCHS_STANDARD) to no avail. I have also tried all of the potential solutions I could find on SO, most of which are pretty old.
Any and all suggestions would be greatly appreciated.
As mentioned in the comments and the edit, you have to build a fat library, but there are steps missing in all of the answers and many of them are badly out of date. Hopefully this will help.
Build a version of the static library for iPhoneOS and iPhoneSimulator.
On the command line, cd to the derived data directory for your project.
You will see directories for the OS and simulator libraries.
Execute the lipo command as below
lipo -create -output [desired fat library name] [path to iPhoneOS library] [path to iPhoneSimulator library]
Drag the fat library from finder to your target project.
You can probably automate this with a build script, but I was under a deadline so it was faster to just build and drag. If you come up with a good script, feel free to post it here.
P.S. The script presented in the Agile Warrior post did not work.

xcodebuild not creating x86_64 binary

I have a strange issue when trying to compile a static library using xcodebuild.
Project's configuration is:
ARCHS = $(ARCHS_STANDARD)
VALID_ARCHS = $ARCHS
It's executed using Xcode 5.1.1.
Now comes the weird part - the project built on machines connected to Jenkins produces fat libary with all 5 architectures (armv7 armv7s arm64, i386, x86_64), but when a build is launched on my (64bit) Mac I'm getting only four - x86_64 is missing. No code change, clean repo, exactly the same build routine.
I wonder what may be causing that difference. I guess it might be some kind of an environment setup on my side, but have no idea what it might be. Project configuration is not under suspicion - it creates proper fat library on a different machine.
I'd be thankful for your advices.
EDIT: No error is thrown either. xcodebuild behaves just like that architecture is not specified - compiles iphonesimulator build just for i386.
Also worth noticing - Xcode creates all architectures, only xcodebuild executed from command line has issues.
Try adding the -destination flag to your xcodebuild command.
xcodebuild -workspace MyWorkspace.xcworkspace -scheme MyScheme -destination 'platform=OS X,arch=x86_64' test
The above is an example from the xcodebuild manual page.
I had a similar issue where I wanted xcodebuild to make an i386 build for simulator and continued to create Armv7 until I added that flag to my command.

Error when trying to archive xcode project

My project runs fine when I run it using the iPhone simulator, and when I run it on a device. When I try to archive it for submission, I get this error:
clang: error: linker command failed with exit code 1 (use -v to see invocation)
This was directly before the error and I'm not sure if it's related:
ld: file is universal (2 slices) but does not contain a(n) armv7s slice: /Volumes/Macintosh HD/Users/dog94a/Google Drive/Capstone/Backups/Approach/Approach/GMaps/GoogleMaps.framework/GoogleMaps for architecture armv7s
The default behavior of the Debug build configuration is to only build the active architecture (Build Active Architecture Only build setting is YES). This is not the case for the Release build configuration, which will build all architectures supported by your Valid Architectures build setting. What this means is that you're likely not targeting an armv7s device during your Debug builds (iPhone 5, latest iPad, etc), so you're not attempting to build that architecture until you do an archive which uses the Release build configuration by default.
The error indicates that your project is configured to create a binary that has armv7s instructions for when it runs on devices of that type, but the GoogleMaps.framework binary you're trying to link against was not built with an armv7s slice. To fix this, you either have to update to the latest version of the GoogleMaps.framework and hope they built it with armv7s enabled, or remove armv7s from your Valid Architectures build setting (obviously the former is preferable).
Once I have included a framework and at compile time nagged the linker for armv7. Now you have armv7s, which is the iphone5?
Solution to my problem it was: remove all files from that framework.
Compile that framework ( double check at Valid architectures settings to be there the desired architecture
Re-add the newly compiled framework.
Try and maybe it helps or even solve your problem too!

OpenCV - file was built for unsupported file format which is not the architecture being linked (i386)

I followed this tutorial : http://tilomitra.com/opencv-on-mac-osx/ to compile OpenCV for Mac OSX in order to use it in XCode 3.2.3
I had no error when compiling openCV. But in XCode I get file was built for unsupported file format which is not the architecture being linked (i386) for each dylib and Symbols not found after.
Any clue ?
steps to compile and run c++ opencv 2.4.4 on mac os x lion 10.7.5 with cmake 2.8.10 and xcode 4.6.1
Having the right tools
download opencv-unix from http://sourceforge.net/projects/opencvlibrary/files/ and untar it wherever
download cmake .dmg from http://www.cmake.org/cmake/resources/software.html and install it
i am assuming you have xcode 4.6 on os x lion which includes the ios sdk 6.1
go to xcode preferences to download and install the Command Line Tools so you have g++ etc.
Use cmake to compile opencv
go to the extracted opencv folder
create a build directory
mkdir build
cd build
cmake -D WITH_TBB=OFF -D BUILD_NEW_PYTHON_SUPPORT=OFF -D BUILD_FAT_JAVA_LIB=OFF -D BUILD_TBB=OFF -D BUILD_EXAMPLES=ON -D CMAKE_CXX_COMPILER=g++ CMAKE_CC_COMPILER=gcc -D CMAKE_OSX_ARCHITECTURES=x86_64 -D BUILD_opencv_java=OFF -G "Unix Makefiles" ..
make -j8
sudo make install
from the build folder, go to bin/ and run one of the tests
./opencv_test_stitching
Create your own c++ opencv xcode project
fire up xcode and create a new xcode project
select Command Line Tool for the type of project under os x
open your project's build settings
under Architectures, set Architecture to 64-bit intel. also set Valid Architectures to x86_64
under Build Options, set Compiler for C/C++ to Default Compiler
under Search Paths, set Header Search Paths to /usr/local/include
also under Search Paths, set Library Search Paths to /usr/local/lib
under Apple LLVM compiler 4.2 - Language set C++ Standard Library to libstd++
Add the compiled opencv libraries to your project
go to the Build Phases tab next to Build Settings tab you were in
inside Link Binary With Libraries, click on the + sign and choose Add Other
hit the front slash / on your keyboard and enter /usr/local/lib
hit enter and select the libraries you want to use in your project
make sure you always select libopencv_core.2.4.4.dylib
hit enter and you will see the selected dylibs under your project
write some code
first lets organize the files, right click on your project blueprint icon and select New Group
name the new group opencv or whatever
drag the dylibs and drop them in that group
open main.cpp
copy code from any of the sample tests that came with opencv and paste it here
make sure all the required dylibs are added, for example, if you copied the opencv_test_stitching.cpp code into main.cpp, you will need to add the following libraries in the previous steps
libopencv_core.2.4.4.dylib
libopencv_highgui.2.4.4.dylib
libopencv_stitching.2.4.4.dylib
Cheers.

Resources