Build armeabi instead of armeabi-v7a target using arm clang toolchain - clang

I followed the article "Standalone Toolchains" to create seven customized toolchains (armeabi, armeabi-v7a, arm64-v8a, misp, mips64, x86, and x86_64). Then I want to build PROJ.4 library. I know ARM clang toolchain by default targets armeabi-v7a, so in order to target armeabi, I use the following commands:
export CFLAGS="-march=arm -O2"
export CC=~/Android/toolchain/arm/bin/clang
export CXX==~/Android/toolchain/arm/bin/clang++
./configure --host=arm-linux-androideabi
Then I get the errors:
clang38: error: the clang compiler does not support '-march=arm'
If I change CFLAGS to "-march=arm-v7a -O2", there would be no errors. But it targets armeabi-v7a, not armeabi. So what is the value for -march flag targeting armeabi?

Try armv5 instead, as described here:
https://developer.android.com/ndk/guides/abis.html

Related

Build C Library from makefile for ios and not macos

I have a makefile that builds some C files and if I run it on an M1 mac the resulting library has the architecture arm64 which I thought it what is necessary for them to compile with an Xcode project for iOS. I discovered I can run the command otool -l libf2c.a | grep platform which should tell me what it was compiled for and in my case it returns platform1 which indicates macOS. Based on this, I think I need a value of platform2 for iOS.
The reason this is an issue is because in Xcode I get the error ld: building for iOS, but linking in object file built for macOS, file '/Users/e.../close.o' for architecture arm64.
Based on what I have been researching it seems iOS and macOS have the same architecture (arm64) but are a different 'platform'? But, I am not sure how the platform is determined. Is there some setting in my makefile I need to specify the platform? I am assuming that if I am able to get the platform to be iOS then Xcode will cooperate and be able to build the library I have generated.
The preferred way to compile for iOS via command line would probably be to use the xcrun command. This will allow you to specify the correct SDK for the platform you actually want to run on. For example:
prompt$ xcrun --sdk iphoneos --toolchain iphoneos clang -c test.c -o test.o -arch arm64
prompt$ otool -v -l test.o | grep platform
platform IOS
TL;DR: change your compiler invocation from plain clang to xcrun --sdk iphoneos --toolchain iphoneos clang.

clang target option for riscv64 doesn't work

I'm trying to use clang to make IR for riscv64.
When I use llc --version, it shows many targets including riscv64.
But when I use the following command:
clang -target riscv64 hello.c
clang -target riscv64-unknown-linux hello.c
It shows clang-4.0: error: unknown target triple 'riscv64-unknown-linux', please use -triple or -arch
I'm not using ucb-bar's llvm for riscv. I'm using riscv from upstream of llvm.org.
Did I do something wrong or do I have to do something before building llvm?
Try elf instead of linux.
clang -target riscv32-unknown-elf
clang -target riscv64-unknown-elf
Edit: I created this repo for everyone interested in using RISC-V with LLVM.

xcodebuild build failed with Xcode 7.1 and iOS 9.1 for iOS project with Cordova

I am trying to build iOS projects from the command line as part of a CI system. I intend to use the xcodebuild command to get an app file, then the app file will be provided to the xcrun command to get a signed ipa file for distribution.
My projects use Cordova, which is located in the folder <project-folder>/CordovaLib.
In the project folder, I executed the following command from within an Ant script:
xcodebuild -target "<project-name>" -configuration Release clean build
The CordovaLib target was built succesfully, and it was produced the file:
<project-folder>/CordovaLib/build/Release-iphoneos/libCordova.a
This is visible by the following snippet of log:
[exec] CreateUniversalBinary build/Release-iphoneos/libCordova.a
normal armv7\ armv7s\ arm64 [exec] cd <project-folder>/CordovaLib
[exec] export
PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/quake/bin:Applications/tools/apache-ant-1.8.4/bin:/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/bin"
[exec]/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool
-static <project-folder>/CordovaLib/build/CordovaLib.build/Release-iphoneos/CordovaLib.build/Objects-normal/armv7/libCordova.a
<project-folder>/CordovaLib/build/CordovaLib.build/Release-iphoneos/CordovaLib.build/Objects-normal/armv7s/libCordova.a
<project-folder>/CordovaLib/build/CordovaLib.build/Release-iphoneos/CordovaLib.build/Objects-normal/arm64/libCordova.a
-o <project-folder>/CordovaLib/build/Release-iphoneos/libCordova.a
During the build of the target <project-name> I got the following error for three times:
ld: file not found:
/build/Release-iphoneos/libCordova.a clang: error:
linker command failed with exit code 1 (use -v to see invocation)
And finally:
The following build commands failed: Ld
build/HelloWorldProjectHelloWorldIpad.build/Release-iphoneos/HelloWorldProjectHelloWorldIpad.build/Objects-normal/armv7/HelloWorld
normal armv7 Ld
build/HelloWorldProjectHelloWorldIpad.build/Release-iphoneos/HelloWorldProjectHelloWorldIpad.build/Objects-normal/armv7s/HelloWorld
normal armv7s Ld
build/HelloWorldProjectHelloWorldIpad.build/Release-iphoneos/HelloWorldProjectHelloWorldIpad.build/Objects-normal/arm64/HelloWorld
normal arm64 (3 failures)
So the file libCordova.a was produced in the folder:
<project-folder>/CordovaLib/build/Release-iphoneos
and it was searched instead in:
<project-folder>/build/Release-iphoneos
I'm using Xcode Version 7.1 (7B91b) with iOS 9.1.
Should I set something on Xcode in addition to the parameters I have used in the xcodebuild command from the command line?
Thanks in advance, Simone.
My project comes from a MEAP IDE. I discovered that the auto-generated project file project.pbxproj had this setting for the linker:
OTHER_LDFLAGS=-force_load "$(BUILT_PRODUCTS_DIR)/libCordova.a" -Obj-C
Hence I modified this way the xcodebuild command invocation:
xcodebuild -target "<project-name>" -configuration Release clean build 'OTHER_LDFLAGS=-force_load "$SRCROOT/CordovaLib/build/Release-iphoneos/libCordova.a" -Obj-C'
That resolved my problem.

Using custom built OpenCV for iOS on XCode produces ___sincos_stret undefined symbol

I'm trying to use a C++ static library into my iPhone app which uses a modified version of OpenCV for iOS and I'm stuck with this issue at linking time:
Undefined symbols for architecture armv7:
"___sincos_stret", referenced from:
cv::initInterTab2D(int, bool) in opencv2(imgwarp.o)
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I really do not understand what I'm missing, that function does not seem to be present in OpenCV and I do not find anything meaningful on the web; I'm wondering if it's in some mathematical library, but I haven't found anything yet.
I've compiled OpenCV with Clang and using the default libc++ library.
The libmylibrary.a and the OpenCV2 framework are correctly in the list of linked libraries.
I'm new to XCode, therefore I could have missed something trivial in the compilation of the static library and/or in the linking of it into my project.
I haven't changed the source code of that object as my changes were related to another part of the imgproc module of OpenCV, therefore I guess that this could have happen even using the default version.
Do you have any clues?
For fixing this problem with the Xcode 5 toolchain I specified the minimum supported iOS version as a compiler option to match the configuration in Xcode. For example:
-miphoneos-version-min=5.0
You can add this to the C and CXX flags in the makefile
CFLAGS += -miphoneos-version-min=5.0
CXXFLAGS += -miphoneos-version-min=5.0
For those who don't want to build with lower version of XCode, try changing python build script of OpenCV iOS. In build_framework.py, I added IPHONEOS_DEPLOYMENT_TARGET=6.0 in lines and rebuilt OpenCV for iOS.
os.system("xcodebuild -parallelizeTargets ARCHS=%s -jobs 8 -sdk %s -configuration Release -target ALL_BUILD" % (arch, target.lower()))
os.system("xcodebuild ARCHS=%s -sdk %s -configuration Release -target install install" % (arch, target.lower()))
to get
os.system("xcodebuild IPHONEOS_DEPLOYMENT_TARGET=6.0 -parallelizeTargets ARCHS=%s -jobs 8 -sdk %s -configuration Release -target ALL_BUILD" % (arch, target.lower()))
os.system("xcodebuild IPHONEOS_DEPLOYMENT_TARGET=6.0 ARCHS=%s -sdk %s -configuration Release -target install install" % (arch, target.lower()))
For me that fixed the issue. A nice read on the symbol __sincos_stret
TODO: Though that fixes the issue, in OpenCV.xcodeproj (in build folder) generated from the python script, it still has deployment target as iOS 7.0. There might be a cleaner way.
I ran into this problem after installing the XCode 5 developer preview and building OpenCV with the build_framework.py script. ___sincos_stret appears to be coming from using the new compiler version.
I fixed this problem by changing the path to the command-line tools.
In Terminal, verify the XCode command-line path:
xcode-select --print-path
If it prints a path inside XCode5-DP.app, then switch to the tools for Xcode 4:
xcode-select --switch /Applications/XCode.app/Contents/Developer
And rebuild the framework. Then try recompiling the project.
Per a quick search in support of Adam's question elsewhere, the symbol is defined in [path to SDK]/usr/lib/system/libsystem_m.dylib. Proof:
nm /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/lib/system/libsystem_m.dylib | grep sincos
Rather than sticking to old versions of the tools or SDK, just make sure you're linking against that.

How to build Boost-Libraries for iPhone

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.

Resources