使用c ++ 11在mac os x山狮与日食(朱诺或开普勒) [英] use c++11 on mac os x mountain lion with eclipse (Juno or Kepler)

查看:161
本文介绍了使用c ++ 11在mac os x山狮与日食(朱诺或开普勒)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,大家我只是开始使用c + + 11,我需要uni,一个mac和我熟悉eclipse(我有Juno或Kepler与CDT),但正如我试过我在eclipse中无法正常运行任何c ++ 11功能或编译任何代码,有一个已经在我相同位置的人,请帮助我,认真我已经尝试所有以前的线程,但为我的失望,我仍然编译一切在终端和编辑所有在gedit与不是最舒适的方式,通过我必须用g ++编译 - 4.7作为命令不是g ++意味着仍然我有旧操作系统gnu,请有人只是解释我一步一步我非常沮丧,我请求!!!!



ps。只是澄清我安装gcc 4.7与homebrew,但路径是不同的原始(/ usr / local / bin而不是常规/ usr / bin,我相信eclipse使用和原因,我不能使用它,谢谢你所有人)

解决方案

在尝试不同的事情和花费乏味的时间修复我的问题后,我会回答我自己的问题,希望有人与我相同的需求不会尝试这样令人讨厌的情况。



首先,在许多论坛评论,是众所周知的gcc编译器提供的Mac OS是旧的,过时的(5年以上是很多计算术语),所以第一步使用c ++ 11是获取一个新版本的gcc。



是两个选项与包公共经理(自制和macports),我不得不说,我是那么沮丧,我试图两个看看是否是在包管理器的一个问题,甚至认为应该是相同的,但对于我的惊喜有一个小的区别,后面我会解释,这使我建议使用macport,因为与macports eclipse将工作作为与旧的c ++光滑,而与homebrew安装将编译将是相同的macport,但eclipse将会抱怨c ++ 11中的新语法(eclipse会告诉你该资源无法解析,即使编译正确)。



这是假设您已经有命令行:


  1. 从官方网页(google it)下载相应的macport

  2. 在终端中键入以下命令


    • sudo port selfupdate

    • sudo端口升级过时

    • sudo port install -d gcc47

    • port select --list gcc


这里你有gcc,并将显示你是哪些是gcc安装在你的mac现在只是缺少选择作为defauld新的gcc,做它。
- sudo port select gcc mp-gcc47



3在我的案例中安装了eclipse kepler创建一个新的C ++项目,而是留下一切标准做下一个:
- 在向导窗口中选择作为工具链的交叉GCC作为工具链(例如ni的可执行文件Hello World c ++项目),放一个随机名称,然后下一个窗口按下一个窗口现在这里在选择的编译器给新的gcc(默认为/ opt / local / bin)作为前缀的路径留空,现在按完成。



转到项目属性和在c / c + +构建选择设置和在工具设置选项卡中去跨g ++编译器和其他标志添加-std = c ++ 11。



5最后一步到c / c ++ general - >路径和符号,选择标签符号,然后选择gnu c ++语言,并按add键将 GXX_EXPERIMENTAL_CXX0X 作为名称,然后按ok 。



现在只需按下apply和ok,之后你的mac应该在eclipse中运行c ++ 11.



Hope为你工作,因为我看到你周围的人。



注意,也许你会配置运行,但它比你只是去运行更简单 - >运行配置和双击在c / c + +应用程序现在几乎一切都生成你只需要填充第一个标签与输出的编译器的路径(我asumme,你已经构建的项目,将生成可执行文件)通常该文件在项目的debug文件夹中,与编译n的文件名相同。



有一个好人。 p>

hey everyone I am just starting to use c++11, which I need for uni, a have a mac and I am familiarise with eclipse (I have both Juno or Kepler with CDT), but as much as I tried I can not run properly any c++11 features in eclipse or compile any code, there is someone that has been in my same position and please help me, seriously I already try all the previous threads about, but for my frustration i am still compiling everything on terminal and editing all in gedit with is not the most confortable way, by the way I have to compile with g++-4.7 as command not g++ meaning that still I have the old OS gnu,please someone just explain me step by step what to do I am terribly frustrated, I beg!!!!

ps. just clarify i install gcc 4.7 with homebrew but the path is different than the original (/usr/local/bin instead of the regular /usr/bin which I believe eclipse use and the reason I can't work with it, thank you for all guys)

解决方案

Well after trying different things and expending tedious time fixing my issue I will answer my own question with the hope someone with my same needs will not experiment such annoying situation.

First as in a lot of forums remark and is well know the gcc compiler provided for the Mac OS is old and obsolete (more than 5 years old is a lot in computing terms), so first step to work with c++11 is to get a new version of the gcc.

There are two options with the packets common managers (homebrew and macports), I have to say that I was that frustrated that i tried both to see if was a problem of the version in the packet manager even thought should be the same, but for my surprise there is a small difference which later I will explain, which bring me to suggest use macport because with macports the eclipse will work as smooth as with the old c++ while with the installation with homebrew the compilation will be the same than the macport but eclipse will complain about the new grammar in the c++11 (eclipse will tell you that the resource couldn't be resolve, even do compile properly ).

The steps for this are assuming you have the command line already:

  1. download the appropriate macports from the official web page(google it)
  2. in terminal type the following commands
    • sudo port selfupdate
    • sudo port upgrade outdated
    • sudo port install -d gcc47
    • port select --list gcc

with this you have gcc and will show you which are the gcc installed in you mac now just missing select as defauld the new gcc, do it with. - sudo port select gcc mp-gcc47

3 having install in my case eclipse kepler create a new C++ project, but instead to left everything standar do the next: - in the wizard window select as toolchain the cross GCC as the toolchain(for example ni the executable Hello World c++ project), put a random name and next , following window press next now here in the window for the selection of the compiler give the path for the new gcc(the default is /opt/local/bin) as prefix leave it empty and press now the finish bottom.

4 Now go to project properties and in c/c++ build select settings and in the tool settings tab go to miscellaneous in cross g++ compiler and in other flags add -std=c++11.

5 by the last go to c/c++ general -> paths and symbols and select the tab symbols and in select the gnu c++ language and press add to type GXX_EXPERIMENTAL_CXX0X as name just that and press ok.

Now just press apply and ok, after that your mac should be running c++11 in eclipse.

Hope works for you as for me see you around guys.

Note probably you will be to configurate the run but it is more simpler than you thing just go to run -> run configurations and double click in c/c++ application now almost everything is generate for you just you have to fill up the first label with the path to the out put of the compiler (I asumme that you already build the project which will generate the executable file ) normally that file is in the debug folder of the project with the same name than the file compiled n does all.

have a good one guys.

这篇关于使用c ++ 11在mac os x山狮与日食(朱诺或开普勒)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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