启用openmp时出错 - "ld:找不到-lgomp的库"和Clang错误

Dav*_* Li 28 c++ gcc openmp clang osx-mavericks

我试图让openmp在我的程序中运行Mavericks,但是当我尝试使用标志进行编译时,-fopenmp我得到以下错误:

ld: library not found for -lgomp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)

我正在运行的命令是:

gcc myProgram.cpp -fopenmp -o myProgram
Run Code Online (Sandbox Code Playgroud)

此外,当我运行gcc时,我得到了Clang警告,我觉得这很奇怪.并且查看/ usr/bin/gcc它似乎没有链接到Clang.

有关如何修复我的Clang错误并获得openmp编译的任何建议?

Hri*_*iev 27

gcc最新的Xcode套件中的命令不再是LLVM的GCC前端(基于非常旧的GCC 4.2.1),而是符号链接clang.Clang(尚未)支持OpenMP.您必须单独安装另一个版本的GCC,例如,通过本教程或使用任何可用的软件包管理系统(如MacPortsHomebrew).

  • 我用brew来安装gcc49 [`brew install gcc49`],但看起来gcc仍然与Clang相关联.`$ g ++ --version配置: - prefix =/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir =/usr/include/c ++/4.2.1 Apple LLVM 5.0( clang-500.2.79)(基于LLVM 3.3svn)目标:x86_64-apple-darwin13.0.0线程模型:posix`我是否必须以某种方式手动设置gcc的符号链接以使用gcc 4.9而不是clang? (2认同)
  • "Clang不支持OpenMP"仍然是真的吗?看到这个:http://clang-omp.github.io如果我安装了这个,你认为它会破坏Xcode 5吗? (2认同)

Jas*_*ham 13

我最近刚刚攻击了这个问题,并根据官方指示编写了使一切正常运行的过程.

该脚本将所有内容下载到〜/代码中以便于维护,并将正确的环境变量附加到〜/ .profile文件中.对于高级用户,请选择一个您想要安装lib,bin和include的好位置并手动移动它们.该脚本依赖于了解Intel的最新OpenMP运行时,可以在脚本的顶部进行更改.

除了一个小问题之外,脚本应该与vanilla Mavericks一起开箱即用.在OpenML运行时make脚本中,它在指定时不能可靠地接受clang并继续使用默认GCC.因此,如果你没有安装GCC(在Mavericks开箱即用的情况下这是不正常的),它将无法构建.要解决此问题,您必须根据OpenMP的libomp_20131209_oss.tgz构建注释掉两行(如脚本中所述).较新的OpenML版本可能会破坏此脚本,因此在较新版本上使用您自己的风险.

只需将此脚本保存到文件中,运行'chmod + x filename.sh',然后从终端运行'./filename.sh'.构建LLVM和Clang需要一段时间,请耐心等待.

编辑:这个脚本很可能在Yosemite上失败,在更新到OSX 10.10的开发版之后,我遇到了使用构建的clang2的问题.

INTEL_OPENMP_LATEST_BUILD_LINK=https://www.openmprtl.org/sites/default/files/libomp_20131209_oss.tgz
DEST_FOLDER = ~/code
CLANG_INCLUDE=${DEST_FOLDER}/llvm/include
CLANG_BIN=${DEST_FOLDER}/llvm/build/Debug+Asserts/bin
CLANG_LIB=${DEST_FOLDER}/llvm/build/Debug+Asserts/lib
OPENMP_INCLUDE=${DEST_FOLDER}/libomp_oss/exports/common/include
OPENMP_LIB=${DEST_FOLDER}/libomp_oss/exports/mac_32e/lib.thin

mkdir ${DEST_FOLDER}
cd ${DEST_FOLDER}
git clone https://github.com/clang-omp/llvm
git clone https://github.com/clang-omp/compiler-rt llvm/projects/compiler-rt
git clone -b clang-omp https://github.com/clang-omp/clang llvm/tools/clang
cd llvm
mkdir build
cd build
../configure
make
cd Debug+Asserts/bin
mv clang clang2
rm -rf clang++
ln -s clang2 clang2++
echo "LLVM+Clang+OpenMP Include Path : " ${CLANG_INCLUDE}
echo "LLVM+Clang+OpenMP Bin Path     : " ${CLANG_BIN}
echo "LLVM+Clang+OpenMP Lib Path     : " ${CLANG_LIB}

cd ${DEST_FOLDER}
curl ${INTEL_OPENMP_LATEST_BUILD_LINK} -o libomp_oss_temp.tgz
gunzip -c libomp_oss_temp.tgz | tar xopf -
rm -rf libomp_oss_temp.tgz
cd libomp_oss

echo "You need to do one or two things:"
echo "1.) [Required] Comment out line 433 from libomp_oss/src/makefile.mk"
echo "2.) [Optional] If you do not have GCC installed (not normal on vanilla Mavericks), you must comment out lines 450-451 in libomp_oss/tools/check-tools.pl.  Have you done this or want to compile anyway?"
select yn in "Yes" "No"; do
    case $yn in
        Yes ) make compiler=clang; break;;
        No ) exit;;
    esac
done

echo "OpenMP Runtime Include Path : " ${OPENMP_INCLUDE}
echo "OpenMP Runtime Lib Path     : " ${OPENMP_LIB}

(echo 'export PATH='${CLANG_BIN}':$PATH';
    echo 'export C_INCLUDE_PATH='${CLANG_INCLUDE}':'${OPENMP_INCLUDE}':$C_INCLUDE_PATH'; 
    echo 'export CPLUS_INCLUDE_PATH='${CLANG_INCLUDE}':'${OPENMP_INCLUDE}':$CPLUS_INCLUDE_PATH';
    echo 'export LIBRARY_PATH='${CLANG_LIB}':'${OPENMP_LIB}':$LIBRARY_PATH';
    echo 'export DYLD_LIBRARY_PATH='${CLANG_LIB}':'${OPENMP_LIB}':$DYLD_LIBRARY_PATH}') >> ~/.profile
source ~/.profile

echo "LLVM+Clang+OpenMP is now accessible through [ clang2 ] via terminal and does not conflict with Apple's clang"
Run Code Online (Sandbox Code Playgroud)


Anv*_*aka 5

如果您正在运行自制程序,则可以通过调用以下方法解决此问题:

brew install clang-omp
Run Code Online (Sandbox Code Playgroud)

编译器将以clang-omp++名称提供

  • 我得到`错误:没有名为"clang-omp"的公式 (2认同)