Re: fixing AC_OPENMP for Apple clang

Dima Pasechnik <[email protected]> Wed, 4 Mar 2026 10:51:34 -0600
Newsgroups gmane.comp.sysutils.autoconf.general
Message-ID <aahjFki-Ij-Djiry@tarski>
--1tbxNXaEs7Owz+wn
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Mar 04, 2026 at 11:45:45AM +0100, Bruno Haible wrote:
> Dima Pasechnik wrote:
> > Apple lies to us here!
> > I have "Apple clang version 17.0.0 (clang-1700.6.3.2)" on the latest ve=
rsion of Intel macOS=20
> >=20
> >   % uname -a
> >   Darwin OUCL13243.local 24.6.0 Darwin Kernel Version 24.6.0: Mon Jan 1=
9 22:00:10 PST 2026; root:xnu-11417.140.69.708.3~1/RELEASE_X86_64 x86_64
> >=20
> >   % cc -v
> >   Apple clang version 17.0.0 (clang-1700.6.3.2)
> >   Target: x86_64-apple-darwin24.6.0
> >   Thread model: posix
> >   InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/X=
codeDefault.xctoolchain/usr/bin
> >=20
> > and "cc -help" reports that "-fopenmp" is an option,
> >=20
> >    % cc --help | grep "fopenmp "
> >   -fopenmp                Parse OpenMP pragmas and generate parallel co=
de.
> >=20
> >=20
> > yet it does not work:
> >=20
> > % cat foo.c
> > #include <stdio.h>
> >=20
> > % cc -c foo.c -fopenmp
> > clang: error: unsupported option '-fopenmp'
>=20
> Similarly for me. My test program actually exercises OpenMP functionality:
>=20
>   $ cat foo.c
>   #include <omp.h>
>   int main (void) { return omp_get_num_threads (); }
>=20
> and I see that the option, while accepted, has no effect:
>=20
>   $ cc -v
>   Apple clang version 17.0.0 (clang-1700.6.3.2)
>   Target: arm64-apple-darwin25.2.0
>   Thread model: posix
>   InstalledDir: /Library/Developer/CommandLineTools/usr/bin
>=20
>   $ cc --help | grep "fopenmp "
>     -fopenmp                Parse OpenMP pragmas and generate parallel co=
de.
>=20
>   $ cc -fopenmp foo.c
>   clang: error: unsupported option '-fopenmp'
>   clang: error: unsupported option '-fopenmp'
>=20
>   $ cc -Xpreprocessor -fopenmp foo.c
>   foo.c:1:10: fatal error: 'omp.h' file not found
>       1 | #include <omp.h>
>         |          ^~~~~~~
>   1 error generated.
>=20
>   $ cc -Xclang -fopenmp foo.c
>   foo.c:1:10: fatal error: 'omp.h' file not found
>       1 | #include <omp.h>
>         |          ^~~~~~~
>   1 error generated.
>=20
> > % cc -c foo.c -Xclang -fopenmp # this is OK
> > % cc -c foo.c -Xpreprocessor -fopenmp # OK too
>=20
> And what if you take my foo.c? Do you get a link error? Do you have to add
> "-lomp" by hand?

I do have to add -I by hand, to begin with (this is with
Homebrew-installed libomp package, "brew install libomp" will give you
it), and it fails at the linking:

% cc foo.c -Xpreprocessor -fopenmp -I $(brew --prefix)/opt/libomp/include
Undefined symbols for architecture x86_64:
  "_omp_get_num_threads", referenced from:
      _main in foo-9fd8a2.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocat=
ion)

So one needs -lomp with -L added, then it works.
% cc foo.c -Xpreprocessor -fopenmp -I$(brew --prefix)/opt/libomp/include -L=
$(brew --prefix)/opt/libomp/lib -lomp
% ./a.out
%

--------

I am working with codebase that instead of AC_OPENMP uses AX_OPENMP from
Autoconf archives (not sure why), and I patched it so that it works.
(with patched libtool).
https://github.com/sagemath/sage/pull/41626/changes#diff-7b626e958ad6b4d0dd=
f0c437c7736df4625749df80bd66b4591dfe501d936223
Then I understood that certainly AX_OPENMP isn't good enough, as it, after =
the patch,
started to leave various penmp/ litter after itself, whereas AC_OPENMP take=
s care or it.

Dima

>=20
> Bruno
>=20
>=20
>=20

--1tbxNXaEs7Owz+wn
Content-Type: application/pgp-signature; name=signature.asc

-----BEGIN PGP SIGNATURE-----

iQFPBAABCAA5FiEEJVdDnfI7raAa4RJxoksLHjfJBTEFAmmoYxMbFIAAAAAABAAO
bWFudTIsMi41KzEuMTEsMiwyAAoJEKJLCx43yQUxOiMH/1bwqbgD3Uz6J6+XlfUI
M9XYCOnV9RcTg4Ezd7JMMsaQKxGZnt2guDbSicV9YfwNPNCQCm6i6wgxjhJI9aNa
SvKjRdSi0rC0exCYa7R6VX7FX4gZFVgSOCrX74y7wzaMz+RXA3A9xue8TxgNtBt7
LBnRVTgiYgKHzFwJuwsC/Bo5h2SvjOqxP6gHAmb3dUzMivFmmJkxlhYMcSBHJczR
W+sPZwJeeJT0EIHTxUBoWqxPnCRmyFdVBFdbZpJVRwx++W9owhCg40JKr/hr3aVC
19bT6UmRpBbaqwZzL66RbgNK2uMZFyT46E1m9w1ZlrhuZO27KT1INDTbFReUE3DL
X+Q=
=Ncn6
-----END PGP SIGNATURE-----

--1tbxNXaEs7Owz+wn--