使用clang编译时找不到'omp.h'文件 [英] 'omp.h' file not found when compiling using clang

查看:5911
本文介绍了使用clang编译时找不到'omp.h'文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用clang(3.7.0)在我的笔记本电脑上运行linux mint设置一个OpenMP项目。



现在我已经阅读了OpenMP不支持,因此我按照此教程 https://clang-omp.github.io/ 将openMP集成到clang中。



我克隆了源代码,设置环境变量并将-fopenmp标志设置为我的项目,但是我仍然得到错误fatal错误:'omp.h'文件未找到时建立。



我的猜测是我设置环境变量错误。有什么办法检查,如果我把它们放在正确的地方?我已经在.bashrc文件中复制了它们。



编辑:
当我运行$ locate omp.h我得到:

  /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

这里是我的makefile:

 #需要以下项目目录结构:
#/ bin
#/ obj
#/ src

#使用'make remove'清除整个项目

#目标文件名称
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:= $(通配符$(SRCDIR)/ *。cpp)
包含: = $(通配符$(SRCDIR)/ *。h)
OBJECTS:= $(SOURCES:$(SRCDIR)/%。cpp = $(OBJDIR)/%。o)

RM = rm -f

$(BINDIR)/ $(TARGET):$(OBJECTS)
@ $(LINKER)$ @ $(LFLAGS)$(OBJECTS)
@echo链接完成!

$(OBJECTS):$(OBJDIR)/%。o:$(SRCDIR)/%。cpp
@ $(CXX)$(CFLAGS)-c $& -o $ @
@echoCompiled$<successfully!

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

.PHONEY:clean
clean:
@ $(RM)$(OBJECTS)
@echo清理完成!
@ $(RM)tmp_file- *
@echo临时文件已删除!

.PHONEY:remove
remove:clean
@ $(RM)$(BINDIR)/ $(TARGET)
@echoExecutable removed!


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


解决方案

OpenMP在Clang 3.7中得到了很好的支持,但您可能需要启用它:此处


OpenMP 3.1完全支持,但默认情况下禁用。要启用它,
请使用-fopenmp = libomp命令行选项。


另请参阅支持的OpenMP结构的状态以获得更多精度。



所以你不必再克隆clang-omp项目了。



你为你的项目使用什么构建系统,什么

如果使用 Makefile :不要忘记添加 -fopenmp / code>标志。



如果您使用 CMake :您还应该查找正确的OpenMP标志与 FindOpenMP模块,并相应地添加它们。



如果您仍然收到包含错误,那么您的omp.h头文件可能不在clang默认搜索路径中。因此,您应该尝试包括gcc附带的一个,并添加 -I / usr / lib / gcc / x86_64-linux-gnu / 4.8 / include /



因此,在您的情况下,您应该添加以下行:

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


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)

解决方案

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

这篇关于使用clang编译时找不到'omp.h'文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆