使用 Clang 进行编译时"'omp.h' file not found"
"'omp.h' file not found" when compiling using Clang
我正在尝试在运行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,一种解决方案是:
- 通过在 CMake 调用时将其添加到
LLVM_ENABLE_PROJECTS
来确保生成openmp
子项目 - 使用
cmake --build . --target omp
生成该子项目 - 将生成的
omp.h
从 build/projects/openmp/runtime/src/omp.h 复制到 build/lib/clang/10.0.0/include,该路径位于新建的 Clang 的默认搜索路径中。
我以前使用过"将 GCC 的路径添加到每个构建命令的 omp.h "方法,但我发现这更容易。
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- 为什么 VScode 在 .h 文件中显示"'iostream' file not found"?
- GCOV-工具合并:"not a gcov data file"
- 在 Ubuntu 16.04 下运行协程示例会得到"'experimental/coroutine' file not found"
- 如何修复'PCH Warning: header stop not at file scope'
- CMake,QT Quick & Visual Studio:"qrc:/main.qml:-1 File not found"
- 如何修复OSX中的"fatal error: 'sys/epoll.h' file not found"?
- 升级到Xcode 10.1后如何修复"fatal error: 'iostream' file not found"
- 在 macOS Mojave 上安装 sharpSAT - "'gmpxx.h' file not found"
- QT 创建器:无法添加 OpenCV dll 库 ( "File format not recognized" )
- OS X Eclipse C++ "Program File Does Not Exist"
- MinGW在代码块中构建时的ar.exe "could not create temporary file whilst writing archive: no more archived files
- 错误"<url> is not recognized as an internal or external command, operable program or batch file.
- GMOCK 叮当讨厌的错误"/usr/include/limits.h:123:16: fatal error: 'limits.h' file not found"
- 得"does not name a type when using static variable in *.c file"
- 具有链依赖项的简单生成文件。 "linker input file unused because linking not done" 和 g++ -c
- 使用 Clang 进行编译时"'omp.h' file not found"
- 尝试执行文件时出现"sh: ./<file> not found"错误
- 在Swift项目中集成Box2d会出现cassert file not found错误
- 扭矩3D建筑模板项目产生"nfd.h file not found"错误是VS2013