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

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

问题描述

我正在尝试在运行Linux Mint的笔记本电脑上使用clang(3.7.0)设置OpenMP项目.

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

现在我已经了解到不立即支持OpenMP,所以我按照本教程 https://clang-omp.github.io/将openMP集成到clang中.

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.

我已经克隆了源代码,设置了环境变量并在项目中设置了-fopenmp标志,但是在构建时仍然出现错误严重错误:找不到'omp.h'文件".

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.

我的猜测是我设置了错误的环境变量.有什么方法可以检查我是否将它们放置在正确的位置?我刚刚将它们复制到.bashrc文件中.

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.

当我运行$ locate omp.h时,我得到:

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

这是我的制作文件:

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

推荐答案

Clang 3.7很好地支持OpenMP ,但是您可能需要启用它,请参见

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

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

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

另请参见受支持的OpenMP构造的状态以获得更高的精度.

Also see Status of supported OpenMP constructs for more precisions.

因此,您不必再克隆clang-omp项目.

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 ?

如果您使用 Makefile :请不要忘记添加 -fopenmp 标志.

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

如果使用 CMake :还应使用

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

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

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

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

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