在Xcode上使用clang ++编译器运行C ++代码时找不到库

时间:2018-06-10 07:43:55

标签: c++ openmp homebrew clang++ xcode9.4

我刚刚安装了Xcode(现在为9.4)并为FizzBu​​zz(Mac OS High Sierra 10.13.4)创建了演示代码。我使用HomeBrew来准备clang ++编译器。

代码:

int main() {
    int n;
    std::cout << "Enter the integer, or enter the negative integer to quit ";
    std::cin >> n;
    while(n >= 0){ 
        if(n % 3 == 0){
            if(n % 5 == 0){
                std::cout << "You entered " << n << "; the outcome is FizzBuzz" << std::endl;
            }
            else{
                std::cout << "You entered " << n << "; the outcome is Fizz" << std::endl;
            }
        }
        else if(n % 5 == 0){
            std::cout << "You entered " << n << "; the outcome is Buzz" << std::endl;
        }
        else{
            std::cout << "You entered " << n << "; the outcome is neither Fizz nor Buzz" << std::endl;
        }
        std::cout << "More ";
        std::cin >> n;
        }
    return 0;
}

在安装LLVM clang ++和OpenMP之前,代码正常工作。一旦我在构建设置和构建阶段设置了clang ++编译器,上面代码的构建就失败了,这是通过clang ++编译器实现的。消息是:

Ld /Users/chonglinxu/Library/Developer/Xcode/DerivedData/TestFizzBuzz-fjyhbifixvmwzubmzedlbtulonxt/Build/Products/Debug/TestFizzBuzz normal x86_64
cd "/Volumes/Lexar/Xcode C++/TestFizzBuzz"
export MACOSX_DEPLOYMENT_TARGET=10.13
/usr/local/opt/llvm/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -L/Users/chonglinxu/Library/Developer/Xcode/DerivedData/TestFizzBuzz-fjyhbifixvmwzubmzedlbtulonxt/Build/Products/Debug -F/Users/chonglinxu/Library/Developer/Xcode/DerivedData/TestFizzBuzz-fjyhbifixvmwzubmzedlbtulonxt/Build/Products/Debug -filelist /Users/chonglinxu/Library/Developer/Xcode/DerivedData/TestFizzBuzz-fjyhbifixvmwzubmzedlbtulonxt/Build/Intermediates.noindex/TestFizzBuzz.build/Debug/TestFizzBuzz.build/Objects-normal/x86_64/TestFizzBuzz.LinkFileList -mmacosx-version-min=10.13 -Xlinker -object_path_lto -Xlinker /Users/chonglinxu/Library/Developer/Xcode/DerivedData/TestFizzBuzz-fjyhbifixvmwzubmzedlbtulonxt/Build/Intermediates.noindex/TestFizzBuzz.build/Debug/TestFizzBuzz.build/Objects-normal/x86_64/TestFizzBuzz_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -stdlib=libc++ -liomp5 -Xlinker -dependency_info -Xlinker /Users/chonglinxu/Library/Developer/Xcode/DerivedData/TestFizzBuzz-fjyhbifixvmwzubmzedlbtulonxt/Build/Intermediates.noindex/TestFizzBuzz.build/Debug/TestFizzBuzz.build/Objects-normal/x86_64/TestFizzBuzz_dependency_info.dat -o /Users/chonglinxu/Library/Developer/Xcode/DerivedData/TestFizzBuzz-fjyhbifixvmwzubmzedlbtulonxt/Build/Products/Debug/TestFizzBuzz


ld: library not found for -liomp5
clang-6.0: error: linker command failed with exit code 1 (use -v to see invocation)
Command /usr/local/opt/llvm/bin/clang++ failed with exit code 1

我不知道为什么找不到-liomp5的库。 clang ++编译的错误导致了在C ++中创建涉及数据结构和算法的项目的冲突。

如何解决缺少clang ++编译器参考库的错误?我应该卸载并重新安装clang编译器,还是应该解决Xcode上的编译器设置问题?我希望代码能够通过clang ++编译器很好地工作。

0 个答案:

没有答案