Skip to content

Instantly share code, notes, and snippets.

@ijleesw
Created December 4, 2018 14:45
Show Gist options
  • Select an option

  • Save ijleesw/4f863543a50294e3ba54acf588a4a421 to your computer and use it in GitHub Desktop.

Select an option

Save ijleesw/4f863543a50294e3ba54acf588a4a421 to your computer and use it in GitHub Desktop.
Install OpenMP on MacOS
#!/bin/bash
# Install
brew install llvm
brew install libomp
# Compile
# clang++ test.cpp -o test -Xpreprocessor -fopenmp -lomp
@snej
Copy link

snej commented Dec 13, 2023

You have to add Homebrew's include and lib directories to Clang's header and library search paths:

-L/opt/homebrew/opt/libomp/lib -I/opt/homebrew/opt/libomp/include

@antongryban
Copy link

(base) antongryban@Antons-MacBook-Air ~ % brew install llvm
brew install libomp
zsh: command not found: brew
zsh: command not found: brew

@siwonpawel
Copy link

siwonpawel commented Dec 21, 2023

This is how it worked for me:

install https://brew.sh/

Install required packages
brew install llvm libomp

in command line set variables that will be used for compilation (can be done by editing .zprofile):

export PATH="/opt/homebrew/opt/llvm/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/llvm/lib"
export CPPFLAGS="-I/opt/homebrew/opt/llvm/include"

compile program
clang++ -fopenmp --std=c++11 -stdlib=libc++ lab04.cpp -o lab04 && ./lab04

@snej
Copy link

snej commented Dec 22, 2023

@kanglicheng
Copy link

This is how it worked for me:

install https://brew.sh/

Install required packages brew install llvm libomp

in command line set variables that will be used for compilation (can be done by editing .zprofile):

export PATH="/opt/homebrew/opt/llvm/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/llvm/lib"
export CPPFLAGS="-I/opt/homebrew/opt/llvm/include"

compile program clang++ -fopenmp --std=c++11 -stdlib=libc++ lab04.cpp -o lab04 && ./lab04

worked perfectly for me.
clang++ -fopenmp proj.cpp -o proj

@eriktrom
Copy link

yeah works perfect

@HeartLaughter
Copy link

it works fine for me, thx alot

@mforotan
Copy link

Does anyone know how to install Libomp without homebrew?
I do not want to use homebrew on my Mac for some limitations.

@db7
Copy link

db7 commented Nov 2, 2025

@mforotan - I am using https://pkgsrc.org for that. It has binary packages for macOS. However, I prefer installing the packages in ~/.local, so I do the pkgsrc manual builds:

  • download pkgsrc source .tgz of a stable version and uncompress somewhere, eg, ~/pkgsrc or /usr/local/pkgsrc.
  • bootstrap: cd pkgsrc/boostrap && ./bootstrap --unprivileged --prefix PREFIX ... (check the options)
  • environment: add PREFIX/bin, PREFIX/lib to your PATH and DYLD_LIBRARY_PATH respectively
  • now you are ready to build packages: cd pkgsrc/parallel/openmp && bmake install

For binary packages check here: https://pkgsrc.smartos.org

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment