使用homebrew,gcc和llvm与C ++ 11 [英] Using homebrew, gcc and llvm with C++ 11

查看:236
本文介绍了使用homebrew,gcc和llvm与C ++ 11的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是我的问题:我想使用由gcc或clang提供的C ++ 11功能。不过,我有这些要求:


  1. 我使用的是mac

  2. 在一堆由homebrew提供的库(和真的不想自己编译它们)。特别是OSG,它本身依赖于大量的其他库。 < / li>

Homebrew似乎只想使用gcc错误)。我找不到任何选项切换到LLVM。虽然我明白,这可能是由于不是所有的库都与LLVM兼容的事实,这对于那些是仍然是一个很好的功能。



版本的gcc预安装在gcc的mac上是4.2。 gcc 4.2没有要求的c ++ 11功能。我已经安装4.7通过homebrew,但搜索如何设置homebrew使用它所有说不要做它(gcc 4.2在mac上不是香草版本,所以4.7版本我将无法编译一些事情)。



我的问题是:任何人有任何建议或修复,他们实现了解决这个问题吗?我应该放弃自制吧?有没有人知道Homebrew是否有计划在未来切换到LLVM?有没有任何人有任何升级计划如何处理这些不兼容?



我不知道自制啤酒可以继续依赖gcc 4.2从长远来看,但

解决方案

Mac上的默认GCC不是GNU的真正GCC。它是LLVM-GCC其实,它是GCC的一个分支。几年前,LLVM-GCC终止,并替换为 DragonEgg ,它是一个使用LLVM作为GCC后端的GCC插件。 p>

LLVM-GCC只是一个编译器前端,其作用是使用GCC frontend将源代码翻译成LLVM IR [ LLVM简介 11.3]。一旦IR生成,LLVM后端将使用它来生成二进制代码。这个步骤与GCC无关。



上面的目标是从10.7完全实现的,其组件都由clang编译,由LLVM提供的前端。



但苹果仍然保留LLVM-GCC和GCC运行时库。我想它的目的可能是提供一个机会来编译一些代码GCC ONLY。



现在让我们回答你的问题:




  • 如果要使用C ++ 11功能,请改用 clang ++ -stc = c ++ 11 -stdlib = libc ++ clang可能已支持所有c ++ 11功能

  • 如果你想要自制软件支持LLVM,它已经支持,至少在后端。

  • 如果你想自制软件使用clang作为编译器前端,它取决于homebrew社区时间表。例如,你可以附加 - with-c ++ 11 参数来使用clang来编译boost.But当你不能使用这个参数 brew install Autoconf 。实际上,某些组件可能无法通过clang正确编译。

  • 如果您知道它可以通过clang编译,但homebrew尚未支持,则必须破解相应的ruby脚本 $ HOMEBREW_ROOT / Library / Formula 目录。幸运的是,在大多数情况下,用 ./ configure blablabla 替换 ./ configure blablabla CXX = clang ++ -stc = c ++ 11 -stdlib = libc ++ 效果很好。顺便说一句,如果您的黑客行为成功,请向自制软件发出拉取请求。



所以,尝试一下,有趣。


Here's my problem: I want to use C++11 features provided by either gcc or clang. However, I have these requirements:

  1. I'm using a mac
  2. I'm dependent on a bunch of libraries provided by homebrew (and really don't want to compile them myself). Specifically OSG, which itself is dependent on a ton of other libraries. And boost, though I can always compile that myself.

Homebrew seems to only want to use gcc (please correct me if I'm wrong). I can't find any options to switch to LLVM instead. While I understand that this might be due to the fact that not all libraries are compatible with LLVM yet, this would still be a nice feature for those that are.

The version of gcc that comes pre-installed on a mac of gcc is 4.2. gcc 4.2 doesn't have the c++11 features required. I've installed 4.7 via homebrew, but searches for how to set homebrew to use it all say don't do it (gcc 4.2 on the mac is not the vanilla version, so the 4.7 version I got won't be able to compile some things).

My questions are: Does anyone have any suggestions or fixes they have implemented to get around this problem? Should I give up on Homebrew? Does anyone know if Homebrew has a plan to switch to LLVM in the future? Does anyone have any upgrade-plan for how to deal with these incompatibilities?

I don't see how homebrew can continue to depend on gcc 4.2 in the long run, but haven't found any real discussion on this matter.

解决方案

The default GCC on Mac is not real GCC of GNU. It's LLVM-GCC in fact, which is a branch of GCC. Several years ago, LLVM-GCC was terminated, and replaced with DragonEgg, which is a GCC plugin to use LLVM as a GCC backend.

LLVM-GCC is just a compiler frontend, whose role is using GCC frontend to translate the source code into LLVM IR[Intro to LLVM 11.3]. Once IR generated, LLVM backend will use it to generate binary code. This step has nothing to do with GCC.

The above goal was fully achieved from 10.7, whose components were all compiled by clang, a frontend provided by LLVM.

But Apple still kept LLVM-GCC and GCC runtime libraries. I guess its purpose might be providing a opportunity to compile some code GCC ONLY.

Now let's answer your questions:

  • If you want to use C++11 features, use clang++ -stc=c++11 -stdlib=libc++ instead. And clang might have already supported all c++11 features.
  • If you want homebrew supporting LLVM, it has already supported, at least on backend.
  • If you want homebrew using clang as a compiler frontend, it depends on homebrew community schedule. For example, you can append --with-c++11 argument to use clang to compile boost.But you cannot use this argument when brew install autoconf. In fact, some components might not be compiled correctly by clang.
  • If you know it can be compiled by clang but homebrew hasn't supported yet, you have to hack the corresponding ruby script at $HOMEBREW_ROOT/Library/Formula directory. Fortunately, in most of cases, replacing ./configure blablabla with ./configure blablabla CXX=clang++ -stc=c++11 -stdlib=libc++ works well. And by the way, if your hack is successful, please make a pull request to homebrew.

So, try it and have a fun.

这篇关于使用homebrew,gcc和llvm与C ++ 11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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