C ++ 20库对xcode 12的支持 [英] c++20 library support for xcode 12

查看:236
本文介绍了C ++ 20库对xcode 12的支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在xcode 12中使用c ++ 20库吗?(xcode 12 beta 5,clang版本10.0.0).

因此在xcode构建设置中,而不是

xcode构建设置中的

 //,"c ++标准库"CLANG_CXX_LIBRARY = libc ++ 

也许使用类似的东西(不起作用=> clang err:无效的库名)

  CLANG_CXX_LIBRARY = libc ++ 20//例如.libc ++ 20和libc ++ 2a是无效的名称 

我已经设置(可以通过提供c ++ 20 语言支持来工作,但是不提供c ++ 20 library 支持)

xcode构建设置中的

 //,"c ++语言方言"CLANG_CXX_LANGUAGE_STANDARD = c ++ 2a//可以,但是不提供c ++ 20库 

我知道c ++ 20库尚未完成/尚未正式发布.

问题:

您知道在xcode 12中使用(初步)c ++ 20库的任何(简便)方法吗?

谢谢

解决方案

可能有更简单的方法,或者我可能做了多余的事情(让我知道可以删除的内容),但这是一个肯定的方法.

使用

构建llvm

  cmake -G"Sublime Text 2-Ninja"-DCMAKE_BUILD_TYPE =发布\-DLLVM_ENABLE_PROJECTS ="clang; libcxx; libcxxabi" -DCMAKE_CXX_STANDARD = 17 -DLLVM_INCLUDE_TESTS = OFF \-DLLVM_TARGETS_TO_BUILD = X86 -DLLVM_CCACHE_BUILD = ON -DLLVM_CREATE_XCODE_TOOLCHAIN = ON \-DCMAKE_INSTALL_PREFIX =易于清洁的位置" \-DLLVM_ENABLE_RTTI =关闭\../llvm 

  • 正常构建项目.但是,由于禁用了索引编制,因此在代码成功构建时,警告可能不会消失.:(添加标题搜索路径有助于警告.


    确保检查功能状态:

    我测试过的代码:

      #include< compare>#include< concepts>struct Aggr {我字符c;自动运算符< =>(Aggr const&)const =默认值;};结构A {int x;int y;int z;};int main(){//A a {.y = 2,.x = 1};//错误;指定者订单与声明不符//命令a b {.x = 1,.z = 2};//好的,b.y初始化为0返回0;} 

    can i use the c++20 library with xcode 12? (xcode 12 beta 5, with clang version 10.0.0).

    so in xcode build settings, instead of

    // in xcode build settings, "c++ standard library"
    CLANG_CXX_LIBRARY = libc++
    

    maybe use something like (does not work => clang err: invalid library name)

    CLANG_CXX_LIBRARY = libc++20 // eg. libc++20 & libc++2a are invalid names
    

    i have already set (works by providing c++20 language support, but does not provide c++20 library support)

    // in xcode build settings, "c++ language dialect"
    CLANG_CXX_LANGUAGE_STANDARD = c++2a // ok but does not provide c++20 library
    

    im aware that the c++20 library is not yet complete/officially released.

    question:

    do you know of any (easy) way to use the (preliminary) c++20 library with xcode 12?

    thanks

    解决方案

    There can be easier ways, or I might have done something redundant (let me know what can be removed), but here's a surefire way.

    Build llvm with

    cmake -G "Sublime Text 2 - Ninja" -DCMAKE_BUILD_TYPE=Release \
    -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi" -DCMAKE_CXX_STANDARD=17 -DLLVM_INCLUDE_TESTS=OFF \
    -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_CCACHE_BUILD=ON -DLLVM_CREATE_XCODE_TOOLCHAIN=ON \
    -DCMAKE_INSTALL_PREFIX="easy to clean location"\
    -DLLVM_ENABLE_RTTI=OFF \
    ../llvm
    

    libcxxabi is required or linking libcxx will fail with:

    ld: library not found for -lcxxabi_shared clang: error: linker command failed with exit code 1 (use -v to see invocation)

    DLLVM_CCACHE_BUILD requires https://ccache.dev (use brew if you wish). First build will be very slow. Rebuilds will be faster.


    After the above is done and ninja compiles around 3000 files, run

     ninja install all 
     ninja install build-xcode-toolchain
    

    Find the created toolchain in location you chose above/Toolchains. Copy it to ~/Library/Developer/Toolchains/


    If Xcode is open, close it and reopen. In Xcode app menu > Toolchains > choose the new one, llvm12git.

    Create a new c++ project normally and go to its project's build settings.

    Search for COMPILER_INDEX_STORE_ENABLE or Enable index-while-building functionality and set it to "No". Otherwise, build fails with "unrecognised option" about indexing.


    Change "C++ language dialect" to "c++20" or "c++2a"

    Build the project normally. However, warnings may not go away while the code successfully builds due to indexing disabled. :( Adding header search path helps with warnings.


    Make sure to check feature status:

    Code I tested:

    #include <compare>
    #include <concepts>
    
    struct Aggr {
      int i;
      char c;
    
      auto operator<=>(Aggr const &) const = default;
    };
    struct A {
      int x;
      int y;
      int z;
    };
    int main()
    {
    
      // A a{.y = 2,.x = 1};  // error; designator order does not match declaration
      // order
      A b{.x = 1, .z = 2};  // ok, b.y initialized to 0
      return 0;
    
    }
    

    这篇关于C ++ 20库对xcode 12的支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆