19

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 the 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 a way to check if I have put them in the right place? I have just copied them in the .bashrc file.

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) 
1

3 Answers 3

9

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 precision.

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

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 the 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...] 
Sign up to request clarification or add additional context in comments.

2 Comments

I build with a Makefile. and the only error I get is "src/main.cpp:6:10: fatal error: 'omp.h' file not found #include <omp.h>" . Also where do I need to put the -fopenmp=libomp command line option? I didnt understand
Please provide your Makefile some includes seem to be missed and also verify that your PATH is correct. I ll add an answer.
4

'omp.h' is a C header that comes with the "Mint" libgcc-[version]-dev (RPM-based OSes have this header in a different package, e.g. libgomp-*).

Example libgcc-4.8-dev: /usr/lib/gcc/x86_64-linux-gnu/4.8/include/omp.h

Solution: Install the version for your default GCC: gcc --version

2 Comments

OpenMP is supported in recent versions of Clang and GCC now.
Suggest : CFLAGS=-I/usr/lib/gcc/x86_64-linux-gnu/4.8/include
2

In case the context is a build of Clang from source - one solution is to:

  1. Ensure the openmp subproject is built by adding it to LLVM_ENABLE_PROJECTS at CMake invocation
  2. Build that subproject with cmake --build . --target omp
  3. Copy the generated omp.h from build/projects/openmp/runtime/src/omp.h to build/lib/clang/10.0.0/include, which is in the newly-built Clang's default search path.

I previously used the "add GCC's path to omp.h to every build command" approach, but I found this easier.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.