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

Posted on Jul 31, 2023 7:01 AM

Reply

Similar questions

7 replies

Aug 2, 2023 6:45 PM in response to etresoft

I found the solution. By compiling using gcc-13 and linking using gcc/clang I was able to get my program to run successfully.


At first I used the full path to the quadmath library - /usr/local/Cellar/gcc/13.1.0/lib/gcc/current/libquadmath.0.dylib

in the makefile.


 I then worked out how to create a TBD for it, copied this to the appropriate directory in /Library/Developer/CommandLineTools.


and it worked just fine, too. I haven't been able to make it work with the static library, libquadmath.a, but one can only spend so much time...


Heres the final version of the makefile :


CC=gcc-13
CFLAGS=-Wall -g 
dtmaxmin-128:	dtmaxmin-128.o
	gcc dtmaxmin-128.o -lquadmath.0 -o dtmaxmin-128
	
clean: 
	rm -f dtmaxmin-128 dtmaxmin-128.o


... and here's the output from the make command


(base) Martins-iMac:dtmaxmin maptin$ make -f makefile-128.mak
gcc-13 -Wall -g    -c -o dtmaxmin-128.o dtmaxmin-128.c
gcc dtmaxmin-128.o -lquadmath.0 -o dtmaxmin-128
(base) Martins-iMac:dtmaxmin maptin$ 


... and here's a sample of the output:


C language Data-type maxima, minima and other vital statistics for Mac OS.
System is Darwin on x86_64 hardware
OS Version is Darwin Kernel Version 20.6.0: Thu Jun  8 22:36:09 PDT 2023; root:xnu-7195.141.49.701.4~1/RELEASE_X86_64
Hostname is : Martins-iMac.local

Single   precision max f.point : 3.40282347e+38                               :   32 bits : 7F7FFFFF
Double   precision max f.point : 1.7976931348623157e+308                      :   64 bits : 7FEFFFFF FFFFFFFF
Extended precision max f.point : 1.18973149535723176502e+4932                 :  128 bits : 00000000 00007FFE FFFFFFFF FFFFFFFF
Quad     precision max f.point : 1.18973149535723176508575932662800702e+4932  :  128 bits : 7FFEFFFF FFFFFFFF FFFFFFFF FFFFFFFF

Single   precision min f.point : 1.17549435e-38                               :   32 bits : 00800000
Double   precision min f.point : 2.2250738585072014e-308                      :   64 bits : 00100000 00000000
Extended precision min f.point : 3.36210314311209350626e-4932                 :  128 bits : 00000000 00000001 80000000 00000000
Quad     precision min f.point : 3.362103143112093506262677817321752603e-4932 :  128 bits : 00010000 00000000 00000000 00000000

Single   precision pi          : 3.14159274e+00                               :   32 bits : 40490FDB
Double   precision pi          : 3.1415926535897931e+00                       :   64 bits : 400921FB 54442D18
Extended precision pi          : 3.14159265358979323851e+00                   :  128 bits : 00000000 00004000 C90FDAA2 2168C235
Quad     precision pi          : 3.141592653589793238462643383279502797e+00   :  128 bits : 4000921F B54442D1 8469898C C51701B8

Single   precision 1/3         : 3.33333343e-01                               :   32 bits : 3EAAAAAB
Double   precision 1/3         : 3.3333333333333331e-01                       :   64 bits : 3FD55555 55555555
Extended precision 1/3         : 3.33333333333333333342e-01                   :  128 bits : 00000000 00003FFD AAAAAAAA AAAAAAAB
Quad     precision 1/3         : 3.333333333333333333333333333333333173e-01   :  128 bits : 3FFD5555 55555555 55555555 55555555


Note that extended precision occupies 128 bits (4 x 32 bit words) but only uses the least-significant 80 bits. The unused high-order bits may have random data in them so I deliberately set them to zero for cosmetic reasons only. I used a union between the quad and 4 x 32-bit unsigned integers for this.


Jul 31, 2023 7:16 PM in response to maptin

You are really going to have to do a lot of work trying to get this kind of non-standard code working on a Mac. Apple doesn't support it. And the GCC people don't support Apple. And Homebrew is just a wreck. Virtually every day I see people who've installed Homebrew and then can't do even basic operations.


For something like this, there are no shortcuts. Assuming that GCC actually does support this, and assuming that GCC actually supports it on the Mac, and assuming that GCC supports it on the Mac with Big Sur, you are going to have to install the toolchain properly. This won't be easy. It is far beyond anything that Homebrew supports.

Jun 24, 2024 10:47 AM in response to momovelo

momovelo wrote:

Hello,
Sorry to dig that up but, are you using an Intel chip or an Apple Silicon one?
Thank you.


From the above replies, x86-64 (highlighting added):


ld: unsupported tapi file type '!tapi-tbd' in YAML file '/Library/Developer/CommandLineTools/SDKs/MacOSX11.sdk/usr/lib/libSystem.tbd' for architecture x86_64

OS Version is Darwin Kernel Version 20.6.0: Thu Jun  8 22:36:09 PDT 2023; root:xnu-7195.141.49.701.4~1/RELEASE_X86_64

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Problems using quad precision floating point - __float128 in macOS Big Sur 11.7.8

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.