Problems using quad precision floating point - __float128 in macOS Big Sur 11.7.8
I want to write a simple cli program that uses quad precision floating point. This isn't supported by Apple's Clang (apparently) so I've installed the latest gnu version of gcc using homebrew - GCC-13.1.0. When using this my program compiles OK but I get the following error from the linker:
ld: unsupported tapi file type '!tapi-tbd' in YAML file '/Library/Developer/CommandLineTools/SDKs/MacOSX11.sdk/usr/lib/libSystem.tbd' for architecture x86_64
Here's my makefile:
CC=gcc-13
CFLAGS=-Wall -g -I/usr/local/Cellar/gcc/13.1.0/lib/gcc/current/gcc/x86_64-apple-darwin20/13/include -I/usr/local/Cellar/gcc/13.1.0/lib/gcc/current/gcc/x86_64-apple-darwin20/13/include-fixed
dtmaxmin-128: dtmaxmin-128.o
gcc-13 dtmaxmin-128.o /usr/local/Cellar/gcc/13.1.0/lib/gcc/current/libquadmath.a -o dtmaxmin-128
Note I used "gcc-13" which is the gnu compile v13 installed by home-brew.
I added #include <quadmath.h> to my program and the full search path to this and the GNU versions of the other header files in the makefile as shown above.
If I use just gcc in the makefile (ie. defaults to Clang) I get lots of compiler errors:
/usr/local/Cellar/gcc/13.1.0/lib/gcc/current/gcc/x86_64-apple-darwin20/13/include/quadmath.h:47:26: error: __float128 is not supported on this target
extern __float128 acosq (__float128) __quadmath_throw;
^
In desperation, I also tried gcc-13 for compiling and gcc/Clang for linking. I then get:
gcc dtmaxmin-128.o /usr/local/Cellar/gcc/13.1.0/lib/gcc/current/libquadmath.a -o dtmaxmin-128
Undefined symbols for architecture x86_64:
"___lttf2", referenced from:
___quadmath_printf_fp in libquadmath.a(printf_fp.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [dtmaxmin-128] Error 1
which comes as no surprise but I thought it worth a try.
I tried deleting the Xcode app and the command line tools directories but I then simply get a message telling me to install the command line tools using Xcode-select --install.
So, I am stuck - I can't get my simple program to work. All it does is to print out max and min values for the various data types and does some simple floating-point arithmetic.
I have a simpler version that does not use __float128 and that works fine using Clang.
I want to use the gnu compiler, just like I would on a linux machine, but it seems some default paths are set up pointing to the command line tools directories.
Running xcrun --show-sdk-path reveals:
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk
I think I need to use Xcode-select to change the default active directory, presumably to something that home-brew installed directories, but it's not clear to me exactly where in /usr/local/Cellar/gcc/13.1.0/lib/gcc/current/gcc/x86_64-apple-darwin20/13 I should point it.
I tried setting it to the above, ran my makefile again and got:
xcrun: error: invalid DEVELOPER_DIR path (/usr/local/Cellar/gcc/13.1.0/lib/gcc/current/gcc/x86_64-apple-darwin20/13), missing xcrun at: /usr/local/Cellar/gcc/13.1.0/lib/gcc/current/gcc/x86_64-apple-darwin20/13/usr/bin/xcrun
I finally tried copying quadmath.h and libquadmath.a into (what I think are) the appropriate directories in the Xcode command line tools area, reset the active directory to the Xcode defaults, simplified the makefile to just use -lquadmath and I STILL get the original "unsupported TAPI file type" error.
Any ideas as to how to get around this would be gratefully accepted.
I'm using an iMac running macOS Big Sur 11.7.8
iMac 27″, 11.7