Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libomp header file conflicts with gcc openmp compilation #112107

Closed
2 tasks done
FilipeMaia opened this issue Oct 1, 2022 · 4 comments
Closed
2 tasks done

libomp header file conflicts with gcc openmp compilation #112107

FilipeMaia opened this issue Oct 1, 2022 · 4 comments
Labels
bug Reproducible Homebrew/homebrew-core bug outdated PR was locked due to age

Comments

@FilipeMaia
Copy link

brew gist-logs <formula> link OR brew config AND brew doctor output

HOMEBREW_VERSION: 3.6.3
ORIGIN: https://github.com/Homebrew/brew
HEAD: d5b6b068c15a8df60f0f5e34a4ca80dcf82c48e3
Last commit: 5 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 3d00b39d454e973773f178f5541b1f651912fa65
Core tap last commit: 30 hours ago
Core tap branch: master
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_DISPLAY: /private/tmp/com.apple.launchd.IKLaHGlLyB/org.xquartz:0
HOMEBREW_MAKE_JOBS: 10
Homebrew Ruby: 2.6.8 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: 10-core 64-bit arm_firestorm_icestorm
Clang: 13.0.0 build 1300
Git: 2.32.0 => /Library/Developer/CommandLineTools/usr/bin/git
Curl: 7.77.0 => /usr/bin/curl
macOS: 12.0.1-arm64
CLT: 13.2.0.0.1.1638488800
Xcode: N/A
Rosetta 2: false

$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: A newer Command Line Tools release is available.
Update them from Software Update in System Preferences or run:
  softwareupdate --all --install --force

If that doesn't show you any updates, run:
  sudo rm -rf /Library/Developer/CommandLineTools
  sudo xcode-select --install

Alternatively, manually download them from:
  https://developer.apple.com/download/all/.
You should download the Command Line Tools for Xcode 13.4.


Warning: Some installed kegs have no formulae!
This means they were either deleted or installed manually.
You should find replacements for the following formulae:
  szip

Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected dylibs:
  /usr/local/lib/libspimage.1.dylib

Warning: Unbrewed header files were found in /usr/local/include.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected header files:
  /usr/local/include/spimage.h
  /usr/local/include/spimage/colormap.h
  /usr/local/include/spimage/cuda_util.h
  /usr/local/include/spimage/fft.h
  /usr/local/include/spimage/find_center.h
  /usr/local/include/spimage/hashtable.h
  /usr/local/include/spimage/image.h
  /usr/local/include/spimage/image_filter.h
  /usr/local/include/spimage/image_filter_cuda.h
  /usr/local/include/spimage/image_io.h
  /usr/local/include/spimage/image_noise.h
  /usr/local/include/spimage/image_sphere.h
  /usr/local/include/spimage/image_util.h
  /usr/local/include/spimage/interpolation_kernels.h
  /usr/local/include/spimage/linear_alg.h
  /usr/local/include/spimage/list.h
  /usr/local/include/spimage/map.h
  /usr/local/include/spimage/mem_util.h
  /usr/local/include/spimage/phasing.h
  /usr/local/include/spimage/prtf.h
  /usr/local/include/spimage/sperror.h
  /usr/local/include/spimage/statistics.h
  /usr/local/include/spimage/support_update.h
  /usr/local/include/spimage/time_util.h

Verification

  • I ran brew update and am still able to reproduce my issue.
  • I have resolved all warnings from brew doctor and that did not fix my problem.

What were you trying to do (and why)?

To be able to compile OpenMP programs with both clang and gcc on a system with libomp installed.

What happened (include all command output)?

libomp installs omp.h in /opt/homebrew/include/omp.h
When compiling an OpenMP program which includes omp.h with gcc and using other header files in /opt/homebrew/include/ gcc will use libomp's header file as it takes priority over gcc's built-in omp.h file.
But that header file is incompatible with gcc's libgomp resulting in a broken program.

You the same issue in this bug report for the libomp RPM package for Fedora.

I also came across this issue here.

What did you expect to happen?

The omp.h from libomp should not be used when compiling OpenMP code with gcc.

Step-by-step reproduction instructions (by running brew commands)

Here's a small example of the problem: https://gist.github.com/biochem-fan/31864239460769d2a4a3585e4959d298
@FilipeMaia FilipeMaia added the bug Reproducible Homebrew/homebrew-core bug label Oct 1, 2022
@biochem-fan
Copy link

Because libomp is specific to LLVM and OpenMP is a part of language extensions, it should be installed to /opt/homebrew/Cellar/llvm/X.Y.Z/lib/clang/X.Y.Z/include, not /opt/homebrew/include. This is how the issue is handled in Ubuntu packages, for example.

@cho-m
Copy link
Member

cho-m commented Oct 2, 2022

Because libomp is specific to LLVM and OpenMP is a part of language extensions, it should be installed to /opt/homebrew/Cellar/llvm/X.Y.Z/lib/clang/X.Y.Z/include, not /opt/homebrew/include. This is how the issue is handled in Ubuntu packages, for example.

Homebrew's libomp formula is intended to be used with Apple Clang (Xcode toolchain) since Apple doesn't provide OpenMP. It allows for a lightweight dependency rather than requiring a separate LLVM or GCC installation.

Homebrew's llvm formula comes with its own copy of libomp. So, this is not the same situation as Linux distros like Ubuntu where the libomp is a sub/split package off of LLVM source package.

fd --no-ignore '^omp.h$' /opt/homebrew
/opt/homebrew/Cellar/libomp/14.0.6/include/omp.h
/opt/homebrew/Cellar/gcc/12.2.0/lib/gcc/current/gcc/aarch64-apple-darwin21/12/include/omp.h
/opt/homebrew/Cellar/llvm/15.0.1/lib/clang/15.0.1/include/omp.h
/opt/homebrew/include/omp.h

I guess a possible workaround would be to make libomp keg-only and not symlink the headers/libraries into main prefix, which is how we distribute package on Linux.

Would need to look into risk of breakages from doing this for dependents, in CMake's FindOpenMP logic, and so on.


May want to get some additional feedback from others who may be more familiar with Homebrew's libomp usage.

@fxcoudert
Copy link
Member

libomp being keg-only seems like the right approach to me

@cho-m
Copy link
Member

cho-m commented Oct 13, 2022

Closing as #112390 made libomp keg-only.

Users that now want to link to libomp will need to set additional flags:

==> Caveats
libomp is keg-only, which means it was not symlinked into /opt/homebrew,
because it can override GCC headers and result in broken builds.

For compilers to find libomp you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/libomp/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/libomp/include"

@cho-m cho-m closed this as completed Oct 13, 2022
@github-actions github-actions bot added the outdated PR was locked due to age label Nov 13, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Reproducible Homebrew/homebrew-core bug outdated PR was locked due to age
Projects
None yet
Development

No branches or pull requests

4 participants