gpt4 book ai didi

c++ - "' omp.h ' file not found"使用 Clang 编译时

转载 作者:IT王子 更新时间:2023-10-29 00:06:37 24 4
gpt4 key购买 nike

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

现在我了解到 OpenMP 不立即受支持,所以我遵循了教程 https://clang-omp.github.io/将 OpenMP 集成到 Clang 中。

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

fatal error: 'omp.h' file not found

构建时。

我的猜测是我设置了错误的环境变量。有没有办法检查我是否将它们放在正确的位置?我刚刚将它们复制到 .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 中得到很好的支持,但您可能需要启用它,请参阅 here .

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

另见 Status of supported OpenMP constructs以获得更高的精度。

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

您的项目使用什么构建系统,编译时遇到什么错误?

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

如果您使用 CMake :您还应该使用 FindOpenMP module 寻找正确的 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...]

关于c++ - "' omp.h ' file not found"使用 Clang 编译时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33400462/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com