supporting OpenMP with Apple's clang
Dima Pasechnik <[email protected]> Thu, 26 Feb 2026 14:19:52 -0600
| Newsgroups | gmane.comp.gnu.libtool.general |
|---|---|
| Message-ID | <aaCq6OVW9IjKaV1q@tarski> |
--B2gvswNdA2XjY8Dj
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Hello,
GNU libtool does not support compiling for and linking with llvm's OpenMP library using Apple's
clang compiler, as it requires prefixing the -fopenmp option with
-Xpreprocessor non-standard option.
We have a simple fix for this - which requires patching ltmain.sh, as
shown below (this is against a bit dated libtool version, GNU libtool
2.4.7; for the current stable version, it would be basically the same).
(cf. https://github.com/sagemath/sage/pull/41626)
Would this be acceptable addition to libtool?
Best,
Dima
diff --git a/build-aux/ltmain.sh b/build-aux/ltmain.sh
index 2a50d7f..8c6a8d8 100644
--- a/build-aux/ltmain.sh
+++ b/build-aux/ltmain.sh
@@ -6864,6 +6864,16 @@ func_mode_link ()
# See if our shared archives depend on static archives.
test -n "$old_archive_from_new_cmds" && build_old_libs=yes
+ # make sure "-Xpreprocessor -fopenmp" is processed as one token
+ case "$@" in
+ *-Xpreprocessor\ -fopenmp*)
+ fopenmp_match="-Xpreprocessor -fopenmp"
+ ;;
+ *)
+ fopenmp_match="-fopenmp"
+ ;;
+ esac
+
# Go through the arguments, transforming them on the way.
while test "$#" -gt 0; do
arg=$1
@@ -7347,7 +7357,7 @@ func_mode_link ()
continue
;;
-mt|-mthreads|-kthread|-Kthread|-pthreads|--thread-safe \
- |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
+ |-threads|$fopenmp_match|fopenmp=*|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
func_append compiler_flags " $arg"
func_append compile_command " $arg"
func_append finalize_command " $arg"
@@ -7891,7 +7901,7 @@ func_mode_link ()
found=false
case $deplib in
-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
- |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
+ |-threads|$fopenmp_match|fopenmp=*|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
if test prog,link = "$linkmode,$pass"; then
compile_deplibs="$deplib $compile_deplibs"
finalize_deplibs="$deplib $finalize_deplibs"
--B2gvswNdA2XjY8Dj
Content-Type: application/pgp-signature; name=signature.asc
-----BEGIN PGP SIGNATURE-----
iQFOBAABCAA5FiEEJVdDnfI7raAa4RJxoksLHjfJBTEFAmmgquUbFIAAAAAABAAO
bWFudTIsMi41KzEuMTEsMiwyAAoJEKJLCx43yQUxCWoH+KDHfdLc2DEHFKmCNOcG
dya6ez1BMvcYwhtYu6HzJK0fn2MBPBLtdwDNTI2+Jc7Ayq/JhcCK+oXDzrc1q4jn
n0mqar+9iggMDKRWai0mqeswDjvF3ARSVfOLbtnJmZ+h6BZA++Aj0r7p7BLvBWBi
rBtHyjNQsLWR68IKDO9l9KF1663LW5/Z4cqjEAemWKePiXCcphnd5oeQENxPzGCz
bfX32klfd3mkFi1R1XqLvTqdUk/CpuArBjgpoZoecewtjoVv5FtwLJMXatvyR+9F
FgzIdbDo1GTCe//0k5YiUQEbaIzMS47ZBVaDgOrxAwGZL2XL8TQ6gYHbk1nK5UKE
zA==
=lZ09
-----END PGP SIGNATURE-----
--B2gvswNdA2XjY8Dj--