macOS llvm compilation : ld: library not found for -lomp

Viewed 1473

I have to use openMP for a project with my university. To do that I downloaded llvm using brew and I replaced cc = gcc in the makefile by CC=/usr/local/opt/llvm/bin/clang.

Now it seemed like it was going to work, but I get an unexpected error ld: library not found for -lomp clang-11: error: linker command failed with exit code 1.

When I run llvm-config --system-libs I get : -lm -lz -lcurses -lxml2.

I'm a complete beginner on this subject, but I think I have to install the ld library ? Can anyone help ?

edit: full makefile

C=/usr/local/opt/llvm/bin/clang
CFLAGS = -O2 -fopenmp
LDFLAGS = -fopenmp

EXEC =  bubble.run  \
    mergesort.run   \
    odd-even.run

HEADER_FILES = $(wildcard *.h)

RAND_INIT=0

ifeq ($(RAND_INIT), 1)
$(Initialization of the vector is random)
CONFIG_FLAGS += -DRINIT
endif

all: $(EXEC)

%.run: %.o utils.o
    $(CC) $(LDFLAGS) -o $@ $^

%.o: %.c $(HEADER_FILES)
    $(CC) -c $(CONFIG_FLAGS) $(CFLAGS) $< -o $@

clean:
    rm -f $(EXEC) *.o *~

.PHONY: clean
1 Answers

Solved in the comments by Craig Estey. So here's my tutorial for compiling openMP on macOS.

  1. install llvm with brew install llvm
  2. install libomp with brew install libomp

Now, it clang and clang++ are calling llvm compilation, OpenMP should compile. But that's where I ran into the issue of missing ld linked.

  1. use find /usr/local -xdev -name '*libomp*' to find where libomp is installed, probably at /usr/local/opt/libomp

Now when you compile/in your makefile, use clang instead of cc/gcc and add LDFLAGS += -L <YOUR PATH TO LIBOMP>/libomp/lib and CFLAGS += -I/usr/local/opt/libomp/include to your make file. Compiling should now work.

Related