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.
I'm trying to compile a very small amount of C source into a library that I can use in XCode for an iOS application.
The files are a single .c file and three header files. I'm very new to C, and no matter what I try I can't seem to get them to compile into a library that supports iOS architectures.
The files depend on the openssl library, and I've got that installed and working fine.
I just need to know the process of compiling these four files into a single library. I've found a plethora of information on the subject online, but I can't decipher which parts are necessary for what I'm trying to do.
I've tried the following:
gcc -fPIC -c main.c
gcc -shared -o mylib.so main.o -lcrypto -lssl
which seems to compile it for x86_64, (I've not tested the resulting file, just checked it's arch).
I've also tried
./configure --disable-shared --enable-utf8 --host=arm-apple-darwin CFLAGS="-arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk" CXXFLAGS="-arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk" LDFLAGS="-L." CC="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc" CXX="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++"
which only gives me errors
checking for arm-apple-darwin-gcc... no
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/Users/nathanf/compilec':
configure: error: C compiler cannot create executables
I've been scouring the internet for the last few days trying to figure this out, but it's so convoluted to cross compile just a few files and I'm frustrated so I came here for some input.
Any help would be greatly appreciated.
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'm trying to compile ImageMagick (in particular Magick++) with clang++ and libc++. Therefore I need to pass -stdlib=libc++ to both compiler and linker.
While CXXFLAGS="-stdlib=libc++" works fine for compiling, LDFLAGS="-stdlib=libc++" seems to only affect the C linker.
How to correctly tell ./configure or make to use this flag when linking C++ libraries?
Use both — CXXFLAGS for the C++ compiler and LDFLAGS for the linker:
./configure CXXFLAGS="-O2 -g -stdlib=libc++" LDFLAGS="-stdlib=libc++"
You could try:
LDFLAGS="-Wl,-stdlib=libc++"
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.