使用 Clang 进行编译时"'omp.h' file not found"

"'omp.h' file not found" when compiling using Clang

本文关键字:file not found omp Clang 使用 编译      更新时间:2023-10-16

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

现在我已经读到OpenMP不是立即支持的,所以我按照教程 https://clang-omp.github.io/将OpenMP集成到Clang中。

我已经克隆了源代码,设置了环境变量并为我的项目设置了 -fopenmp 标志,但我仍然收到错误:

致命错误:"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

这是我的制作文件:

# 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 在 Clang 3.7 中得到了很好的支持,但您可能需要启用它,请参阅此处。

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

另请参阅支持的 OpenMP 构造的状态,以获得更高的精度。

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

你为项目使用什么构建系统,编译时会遇到什么错误?

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

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

如果仍然收到包含错误,则 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...]

'omp.h'是一个C头文件,带有"Mint">libgcc-[version]-dev(基于RPM的操作系统在不同的软件包中具有此标头,例如libgomp-*(。

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

解决方案:安装默认 GCC 的版本:gcc --version

libgcc-dev

如果上下文是从源代码构建的 Clang,一种解决方案是:

  1. 通过在 CMake 调用时将其添加到LLVM_ENABLE_PROJECTS来确保生成openmp子项目
  2. 使用 cmake --build . --target omp 生成该子项目
  3. 将生成的omp.h从 build/projects/openmp/runtime/src/omp.h 复制到 build/lib/clang/10.0.0/include,该路径位于新建的 Clang 的默认搜索路径中。

我以前使用过"将 GCC 的路径添加到每个构建命令的 omp.h "方法,但我发现这更容易。

相关文章: