'omp.h' file not found when compiling using clang

LxSwiss picture LxSwiss · Oct 28, 2015 · Viewed 17.5k times · Source

I'm trying to set up an OpenMP project using clang( 3.7.0) on my laptop running linux mint.

Now I've read that OpenMP is not supported right away so I followed this tutorial https://clang-omp.github.io/ to integrate openMP into clang.

I've cloned the source code, set the environment variables and set the -fopenmp flag to my project, but i still get the error "fatal error: 'omp.h' file not found" when building.

My guess is that I have set the environment variables wrong. Is there any way to check if I have put them in the right place? I have just copied them in the .bashrc file.

Edit: when I run $locate omp.h I get:

/usr/include/re_comp.h
/usr/include/linux/ppp-comp.h
/usr/include/linux/seccomp.h
/usr/include/net/ppp-comp.h
/usr/include/openssl/comp.h
/usr/lib/gcc/x86_64-linux-gnu/4.8/include/omp.h
/usr/lib/perl/5.18.2/CORE/regcomp.h
/usr/src/linux-headers-3.13.0-24/arch/arm/include/asm/seccomp.h
/usr/src/linux-headers-3.13.0-24/arch/microblaze/include/asm/seccomp.h
/usr/src/linux-headers-3.13.0-24/arch/mips/include/asm/seccomp.h
/usr/src/linux-headers-3.13.0-24/arch/powerpc/include/uapi/asm/seccomp.h
/usr/src/linux-headers-3.13.0-24/arch/s390/include/asm/seccomp.h
/usr/src/linux-headers-3.13.0-24/arch/sh/include/asm/seccomp.h
/usr/src/linux-headers-3.13.0-24/arch/sparc/include/asm/seccomp.h
/usr/src/linux-headers-3.13.0-24/arch/x86/include/asm/seccomp.h
/usr/src/linux-headers-3.13.0-24/include/linux/ppp-comp.h
/usr/src/linux-headers-3.13.0-24/include/linux/seccomp.h
/usr/src/linux-headers-3.13.0-24/include/net/ipcomp.h
/usr/src/linux-headers-3.13.0-24/include/uapi/linux/ppp-comp.h
/usr/src/linux-headers-3.13.0-24/include/uapi/linux/seccomp.h
/usr/src/linux-headers-3.13.0-24-generic/include/config/seccomp.h
/usr/src/linux-headers-3.13.0-24-generic/include/config/crypto/pcomp.h
/usr/src/linux-headers-3.13.0-24-generic/include/config/inet/ipcomp.h
/usr/src/linux-headers-3.13.0-24-generic/include/config/inet6/ipcomp.h
/usr/src/linux-headers-3.13.0-24-generic/include/config/isdn/ppp/bsdcomp.h
/usr/src/linux-headers-3.13.0-24-generic/include/config/ppp/bsdcomp.h
/usr/src/linux-headers-3.13.0-24-generic/include/config/xfrm/ipcomp.h
/usr/src/linux-headers-3.13.0-24-generic/include/linux/ppp-comp.h
/usr/src/linux-headers-3.13.0-24-generic/include/linux/seccomp.h

here is my makefile:

# Requires the following project directory structure:
#  /bin
#  /obj
#  /src

# Use 'make remove' to clean up the whole project

# Name of target file
TARGET     = main

CXX        = clang++
CFLAGS     = -std=c++11 \
             -Weverything -Wall -Wextra -Wold-style-cast -Wpointer-arith -Wcast-qual \
             -Wno-missing-braces -Wempty-body -Wno-error=uninitialized \
             -Wno-error=deprecated-declarations -Wno-c++98-compat \
             -pedantic-errors -pedantic \
             -Os -fopenmp

LINKER     = clang++ -o
LFLAGS     = -Wall -Weverything -pedantic

SRCDIR     = src
OBJDIR     = obj
BINDIR     = bin

SOURCES   := $(wildcard $(SRCDIR)/*.cpp)
INCLUDES  := $(wildcard $(SRCDIR)/*.h)
OBJECTS   := $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)

RM         = rm -f

$(BINDIR)/$(TARGET): $(OBJECTS)
    @$(LINKER) $@ $(LFLAGS) $(OBJECTS)
    @echo "Linking complete!"

$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.cpp
    @$(CXX) $(CFLAGS) -c $< -o $@
    @echo "Compiled "$<" successfully!"

.PHONEY: prepare
prepare:
    mkdir -p bin
    mkdir -p obj

.PHONEY: clean
clean:
    @$(RM) $(OBJECTS)
    @echo "Cleanup complete!"
    @$(RM) tmp_file-*
    @echo "Temporary files removed!"

.PHONEY: remove
remove: clean
    @$(RM) $(BINDIR)/$(TARGET)
    @echo "Executable removed!"


.PHONEY: run
run:
    ./bin/$(TARGET)

Answer

coincoin picture coincoin · Oct 28, 2015

OpenMP is well supported in Clang 3.7 but you might need to enable it see here.

OpenMP 3.1 is fully supported, but disabled by default. To enable it, please use the -fopenmp=libomp command line option.

Also see Status of supported OpenMP constructs for more precisions.

So you don't have to clone the clang-omp project anymore.

What build system do you use for your project and what errors do you get when you compile ?

If you use Makefile : do not forget to add the -fopenmp flag.

If you use CMake : you should also look for right OpenMP flags with FindOpenMP module and add them accordingly.

If you still get the include error then your omp.h header file may not be in the clang default search path. So you should try to include the one that comes with gcc and add -I/usr/lib/gcc/x86_64-linux-gnu/4.8/include/.

So in your case you should add this line :

CFLAGS = -std=c+11 [etc...]
CFLAGS += -I/usr/lib/gcc/x86_64-linux-gnu/4.8/include/
LINKER = [etc...]