My (built from source) llvm/clang install is able to create 32/64-bit executables fine, but when I created the installation it only produced 64-bit libraries (eg, libclang).
I've sifted through their documentation, looked through the configure help, etc. As best I can tell my only option is to configure targeting a 32-bit host machine and do a separate installation.
I should probably add: there's 32/64-bit sanitizer libraries (eg, libclang_rt.asan-i386.a), it's the rest of the support libraries in question.
Configure LLVM and Clang with -arch i386 -arch x86_64 i.e.:
CFLAGS="-arch i386 -arch x86_64" \
CXXFLAGS="-arch i386 -arch x86_64" \
./configure --prefix=/prefix --enable-optimized --disable-assertions
Related
I've been writing a makefile which will need to compile for multiple platforms. Right now I only need to compile for iOS, but as I already know that I'll need to support Mac OS X in a near future I've also been looking on how to compile for that as well. Notice that I'm not using Xcode. That's not an option as the project will also have to support other platforms.
I already have a makefile compiling for iPhone. It's working (tested on the simulator, even) but I still have a few doubts.
Specifically I've read about many tools and right now I'm a bit confused about some of them:
xcodebuild and clang I get clang, it's a compiler, but what about xcodebuild? Does it just use clang for compiling and also runs some tests? Are there upsides to using? Downsides?
libtool vs ar pretty much the same thing. How do these differ? I've read that ar should be followed by a call to ran lib (although it's not clear on the why), so there must be downsides, but which? Edit: forgot to include lipo in the discussion
Finally, and I hope I'm not getting off topic, I'm generating fat files for iphoneos and iphonesimulator. Here's how; first I compile for each platform:
ifeq ($(ARCH), iphoneos)
ARCHFLAGS = -arch armv7 -arch armv7s -arch arm64
else
ARCHFLAGS = -arch i386 -arch x86_64
endif
ifeq ($(ARCH), iphoneos)
VERFLAGS = -miphoneos-version-min=7.0
else
VERFLAGS = -mios-simulator-version-min=7.0
endif
CC = $(shell xcrun --sdk $(ARCH) --find clang)
CFLAGS := -isysroot $(shell xcrun --sdk $(ARCH) --show-sdk-path)
CFLAGS += $(ARCHFLAGS)
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
$(CC) $(CFLAGS) -c $< -o $#
Some flags, variables, and rules are omitted. This generates two sets of .o files. I then use ar (should it be libtool?):
AR = ar
ARFLAGS = crv
$(BINARY): $(OBJECTS) # This rule depends on the previous one
$(AR) $(ARFLAGS) $(BINARY) $(OBJECTS)
By now I have a static library (.a) file for each platform. I proceed to generate the fat file:
$(LIBTOOL) $(LIBTOOLFLAGS) -o $(call libfile,iphone,debug) $(call libfile,iphoneos,debug) $(call libfile,iphonesimulator,debug)
Note: libfile is a function which returns the file name for the given configuration.
Two questions now:
Could I just skip the generation of the two separate .a files and jump to the the fat file by specifying ARCHFLAGS = -arch armv7 -arch armv7s -arch arm64 -arch i386 -arch x86_64? That is, all platforms in a single call. Is it the same thing?
This was the closest I got to listing supported architectures (not a good option, I'd say). Could I just list all (or a subset) of them, generate an "obese" (lol) file and expect the compiler to optimize the file's size when linked against an actual implementation? Or are fat files shipped with the final product?
Thank you for reading so far.
Best.
I am having trouble building MPFR for iOS, armv7s architecture. I am using this command after successfully building GMP,
./configure CC=clang CPP="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -E" CPPFLAGS="-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.3.sdk/ -miphoneos-version-min=8.0 -arch armv7s -target arm-apple-darwin" --host=aarch64-apple-darwin --disable-assembly --enable-static --disable-shared
However, I configure is giving me the error
libgmp not found or uses a different ABI.
I built GMP with the same configure settings as above, then make, make install, etc. After this, I copied the gmp.h file and libgmp.la file to
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.3.sdk/usr/include/
and
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.3.sdk/usr/lib
respectively, but I get the same error.
Any ideas?
Okay, I think being tired got to me, and I was using an x86_64 version of GMP to try to compile the armv7 mpfr. I retried today, and everything worked. Make sure to move the gmp header and the libgmp.a file to the iOS sdk directories as mentioned in the question, else you will get an error at configure time. Other than that, it should work.
I have a GMP Library that is used for BIG integer calculation in C++.
I am unable to compile the same in Xcode for iOS development.
Please Provide with details steps regarding how to compile GMP for iOS Development
I realize that there has been some considerable time gone by but none of the information in the previous answer worked for me. Here is how I was able to do it, hope this helps someone else in the future.
Grab the gmp snapshot from https://gmplib.org/download/snapshot/
It is in .lz format, it will need to be uncompressed. if you have a mac, uncompress it using lzip, install with homebrew brew install lzip
Once its uncompressed from lzip, then it will be a .tar file, the finder can take care of that for you. You will have a gmp folder with a bunch of files and other sub-folders.
You will need Xcode commandline tools installed. Make sure you have that pre-installed.
Run this configure line. Take care to note that you need to put in your path to the directory you want it to be stored, in --prefix.
./configure CC="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -fembed-bitcode -arch arm64e --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk" CPPFLAGS="-fembed-bitcode -arch arm64e --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk " --disable-shared --enable-static --host=arm-apple-darwin --disable-assembly --prefix="{ YOUR_PATH_HERE }/GMP_6_1_99/gmp-6.1.99-20200117/gmplib-iphoneos-arm64e"
Then you run (notice the same path as before for the log files)
make -j &> "{ YOUR_PATH_HERE }/gmp-6.1.99-20200117/gmplib-iphoneos-arm64e-build.log"
make install &> "{ YOUR_PATH_HERE }/gmp-6.1.99-20200117/gmplib-iphoneos-arm64e-install.log"
There are two main points to those lines that are changeable, the platform, and the architecture. The above uses the arm64e architecture but you can just as easily build for arm64, armv7, armv7s. Also you can change out the platform as well and build for macosx, watchos, iphonesimulator, or appletvos. To change the platform you need to find the sdk of where it lives on your machine. The other architecture options are x86_64 i386, To do that, type this into your terminal...
xcrun --sdk iphoneos --show-sdk-path
(replace "iphoneos" with the platform you are looking to use from above)
And replace the SDK path. Make sure you match with the correct architecture or else you will get an error, cannot find compiler.
As GenieWanted said, provide more information!!!
However, I compiled successfully the GMP library for iOS 7 64 bits following the next step:
./configure
CC="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
CPP="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-E" CPPFLAGS="-target arm64-apple-darwin -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk/
-miphoneos-version-min=7.0" --host=aarch64-apple-darwin --disable-assembly --enable-static --disable-shared --prefix=/your-path/
I would like to point out that it only creates the C library, I do not think is different for C++, however I will try this afternoon.
#bolnad's answer worked for me doing a small modification, removing the -fembed-bitcode flag both from CC and CPPFLAGS.
EDIT: it ended up not correctly compiling the different architectures, so I found this script on github https://github.com/FlowCrypt/GMP and was able to build correctly.
Hope someone can shed a light on this issue for me. I am building ruby 32bit in RHEL 6 x86_64 using rvm. Followed this guide(ignored Mac related stuffs), I ran
rvm_archflags="-arch i386" CFLAGS="-arch i386" LDFLAGS="-arch i386"
rvm install 1.9.2
I get an error like this:
Error running './configure --disable-install-doc --prefix=/home/deploy/.rvm/rubies/ruby-1.8.7-p371 --enable-shared'
Trying original method: rvm install 1.8.7 --32 and got this:
'env MACOSX_DEPLOYMENT_TARGET= CFLAGS=-O3 -arch i386 -g -Os -pipe
-no-cpp-precomp CCFLAGS=-arch i386 -g -Os -pipe CXXFLAGS=-arch i386 -g -Os -pipe LDFLAGS=-arch i386 -bind_at_load LDSHARED=cc -arch i386 -dynamiclib -undefined suppress -flat_namespace ./configure --disable-install-doc --prefix=/home/deploy/.rvm/rubies/ruby-1.8.7-p371 --enable-shared'
Looking at the config.log, it says C compiler cannot create executables. From the look of the errors, I guess it mismatched the target machine(Mac instead of RHEL). I don't quite understand why because the gcc is definitely built for x86_64 Red Hat linux. Can someone give me a hint on this issue?
Thanks alot
Compiling in 32bit requires using the -m32 option on linux. The -arch i386 option is Mac specific.
You will, of course require the full suite of 32bit development libraries.
Can someone tell me, where to find a detailed guide, how to build the Boost-Libraries for using it on the iPhone-Device.
I've allready build the libs for Mac and can use them in my project (only on iPhone-Simulator). While building the project for iPhone-Device, XCode haunts me a warning: "file is not of required architecture" ond some other errors.
Please Help
Start a new project in Xcode using the iPhone Static Library project template.
Then import the source and headers, and compile it that way. The result should be an iPhone compatible static library
I started here:
http://lists.boost.org/boost-build/2009/02/21326.php
With most of Boost you probably don't need to actually compile it, just include the useful headers. In my case, I just did the compiler define in my own Xcode project.
Hey I have updated Pete Goodliffes script in my openFrameworks addon:
It currently has arm64, armv7, i386, x86_64
Boost 1.59.0 or previous
libc++ / std=c++11 -- Now optional release for libstdc++
Precompiled and Script to build yourself (so if you need libstdc++ quite easy to change)
Supports Xcode 7
[https://github.com/danoli3/ofxiOSBoost][1]
For boost libraries which have only headers files (.hpp) you can just set header search path from your project to them.
For boost libraries with sources you can build static libraries for both ios phone/simulator with next simple steps:
Download and unpack a boost release archive (from https://www.boost.org/users/download/) e.g.: https://boostorg.jfrog.io/artifactory/main/release/1.77.0/source/boost_1_77_0.tar.bz2
Run bootstrap.sh with needed libraries to build for instance 'context' (format =library1,library2,...):
./bootstrap.sh --with-libraries=context
Add toolsets with correct paths to installed SDKs to project-config.jam:
# IOS ARM64
using clang : iphoneos
: xcrun clang -arch arm64 -stdlib=libc++ -std=c++11 -miphoneos-version-min=12.0 -fvisibility-inlines-hidden -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk
;
# IOS x86_64
using clang : iphonesimulator
: xcrun clang -arch x86_64 -stdlib=libc++ -std=c++11 -miphoneos-version-min=12.0 -fvisibility-inlines-hidden -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk
;
Create and run build.sh script (where lib name is libboost_<name>.a):
lib=libboost_context.a
dir='stage/lib'
# Build arm64
./b2 -a -j4 toolset=clang-iphoneos binary-format=mach-o abi=aapcs link=static stage
mv $dir/$lib $dir/arm64_$lib
# Build x86_64
./b2 -a -j4 toolset=clang-iphonesimulator binary-format=mach-o abi=sysv link=static stage
mv $dir/$lib $dir/x86_64_$lib
# Make fat
lipo -create $dir/arm64_$lib $dir/x86_64_$lib -output $dir/$lib
Now you have next compiled static libraries in "/stage/lib" dir for boost context: arm64_libboost_context.a, x86_64_libboost_context.a and fat one libboost_context.a.
We use boost too. To simplify its inclusion into new applications I have created a Xcode project you can drop into your workspace to include boost. It is based on a Makefile so you need the Xcode commandline tools installed.
The project is here https://github.com/Cogosense/iOSBoostFramework.
Clone the project into your workspace, then click on Menu File->"Add Files to workspace". Select iOSBoostFramework/iOSBoostFramework.xcodeproj in the file finder and click add.
The Makefile in the iOSBoostFramework directory controls what is built and how it is built. There is support for Xcode workspace dependencies, bitcode generation, and only the target architectures selected by Xcode are built.
The following libraries are built test, thread, atomic, signals, filesystem, regex, program_options, system date_time, serialization, exception, locale, and random.
All the separate libraries and architectures are combined, the final build output is a FAT boost.framework Framework bundle which can be linked into the application.
The version of boost is specified in the Makefile (currently 1.64.0), it is downloaded, built for all active architectures and installed in the BUILT_PRODUCTS_DIR specified by xcode.
The previous answer helped me when I wanted to build boost for the arm simulator. When you have a Mac with M1 processor and want to use the simulator, you cannot use the arm64 build for the iPhone.
I added this to the project-config.jam:
# IOS Arm Simulator
using clang : iphonesimulatorarm64
: xcrun clang -arch arm64 -stdlib=libc++ -std=c++11 -miphoneos-version-min=10.0 -fvisibility-inlines-hidden -target arm64-apple-ios10.0-simulator -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk ;
Then pass toolset=clang-iphonesimulatorarm64 to the b2 command.