如何确定使用哪个 C/C++ 编译器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2806160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I determine which C/C++ compiler to use?
提问by Uri
I am trying to figure out which C/C++ compiler to use. I found this list of C/C++ compilers at Wikipedia:
我想弄清楚要使用哪个 C/C++ 编译器。我在维基百科上找到了这个 C/C++ 编译器列表:
http://en.wikipedia.org/wiki/List_of_compilers#C.2FC.2B.2B_compilers
http://en.wikipedia.org/wiki/List_of_compilers#C.2FC.2B.2B_compilers
I am fairly certain that I want to go with an open source compiler. I feel that if it is open source then it will be a more complete compiler since many programmer perspectives are used to make it better. Please tell me if you disagree.
我相当确定我想使用开源编译器。我觉得如果它是开源的,那么它将是一个更完整的编译器,因为许多程序员的观点都被用来使它变得更好。如果您不同意,请告诉我。
I should mention that I plan on learning C/C++ mainly to program 2D/3D game applications that will be compatible with Windows, Linux, MAC and iPhone operating systems. I am currently using Windows Vista x64 OS.
我应该提一下,我计划学习 C/C++ 主要是为了编写与 Windows、Linux、MAC 和 iPhone 操作系统兼容的 2D/3D 游戏应用程序。我目前使用的是 Windows Vista x64 操作系统。
回答by Uri
First of all, IMHO as a beginner your development environment (IDE) matters a lot more than the compiler.
首先,恕我直言,作为初学者,您的开发环境 (IDE) 比编译器重要得多。
I think that people place too much emphasis on compiler choice early on. While it is not Java, C++ is meant to be portable.
我认为人们在早期就过分强调编译器的选择。虽然它不是 Java,但 C++ 旨在是可移植的。
If the program you're writing only works with specific compilers, you're probably doing the wrong thing or can work a little on making it more portable.
如果您正在编写的程序仅适用于特定的编译器,那么您可能做错了事情,或者可以稍微提高一下它的可移植性。
If you get to a point where compiler choice makes a significant performance impact for you, then you've already perfected everything else in your program and you're in a good state and you are also quite advanced in your abilities. We used to teach the differences between compilers at fairly advanced stages in the CS curriculum.
如果您达到编译器选择对您的性能产生重大影响的地步,那么您已经完善了程序中的其他所有内容,并且您处于良好状态,并且您的能力也相当先进。我们曾经在 CS 课程的相当高级阶段教授编译器之间的差异。
If you use a UNIX based machine (Linux, Mac, actual Linux), then pretty much GNU (g++) is the way to go and is fairly much standard. If it's good enough to compile your OS, it's probably good enough for you. On a mac you can use XCode as your IDE, and it interfaces well with g++. On Linux some people prefer command line tools, though you might like the Eclipse C++ support, it is much better today than it was 3-4 years ago.
如果您使用基于 UNIX 的机器(Linux、Mac、实际的 Linux),那么几乎 GNU (g++) 是可行的方法并且相当标准。如果它足以编译您的操作系统,那么它可能对您来说已经足够了。在 Mac 上,您可以使用 XCode 作为您的 IDE,并且它与 g++ 的接口很好。在 Linux 上,有些人更喜欢命令行工具,尽管您可能喜欢 Eclipse C++ 支持,但它今天比 3-4 年前要好得多。
Things on Windows are trickier. If you can afford it, have access to, or are eligible for one of the free editions (e.g., via a school), I think the Microsoft Visual C++ Environments (or whatever they are called now) are pretty good for learning and they are used in production. I think there's actually a lightweight visual studio now with an emphasis on C++ that could be a good start. If you don't, you can probably find a distribution of Eclipse that is specific for C++ and includes an implementation of the GNU compilers.
Windows 上的事情比较棘手。如果您负担得起、可以访问或有资格获得其中一个免费版本(例如,通过学校),我认为 Microsoft Visual C++ 环境(或现在称为的任何内容)非常适合学习,并且它们是生产中使用。我认为现在实际上有一个轻量级的视觉工作室,重点是 C++,这可能是一个好的开始。如果不这样做,您可能会找到一个特定于 C++ 的 Eclipse 发行版,其中包括 GNU 编译器的实现。
回答by Greg Bacon
Use gcc and g++ while you're still learning these languages, a big enough task for now. If you need a specialized compiler down the road, you'll want to have much deeper understanding of the language and your problem domain to properly evaluate candidates.
在您仍在学习这些语言时使用 gcc 和 g++,这对于现在来说是一项足够大的任务。如果您需要一个专门的编译器,您将需要对语言和您的问题领域有更深入的了解,以正确评估候选人。
回答by Max
Get the Visual Studio Express (easier and quicker IMO, to setup) and learn with it; when you think you know enough about C++ and how "things" work, you could start using something like QT or GCC (with cygwin) and learn to port to different platforms.
获取 Visual Studio Express(在 IMO 中设置更简单、更快捷)并使用它学习;当您认为自己对 C++ 以及“事物”的工作原理了解得足够多时,您可以开始使用 QT 或 GCC(使用 cygwin)之类的东西,并学习移植到不同的平台。
回答by Jesper
I feel that if it is open source then it will be a more complete compiler since many programmer perspectives are used to make it better.
我觉得如果它是开源的,那么它将是一个更完整的编译器,因为许多程序员的观点都被用来使它变得更好。
That's not necessarily true. You could also say that if you use Microsoft's compiler, it will be optimal for Windows, since Microsoft knows best how to optimize a compiler for Windows.
这不一定是真的。您也可以说,如果您使用 Microsoft 的编译器,它将是 Windows 的最佳选择,因为 Microsoft 最了解如何为 Windows 优化编译器。
Microsoft has Visual C++ Express Editionwhich is free and ofcourse includes a nice IDE that's very well suited for Windows development.
Microsoft 有Visual C++ Express Edition,它是免费的,当然包括一个非常适合 Windows 开发的不错的 IDE。
But if you're interested in making portable software, look at GCC, which is the default compiler on Linux and which is also available on the Mac. (The iPhone works totally different and requires special tools that only run on Mac OS X). You can get GCC for Windows with Cygwinor MinGW.
但是,如果您对制作可移植软件感兴趣,请查看 GCC,它是 Linux 上的默认编译器,也可在 Mac 上使用。(iPhone 的工作方式完全不同,并且需要仅在 Mac OS X 上运行的特殊工具)。您可以使用Cygwin或MinGW获得适用于 Windows 的 GCC 。
回答by rabidmachine9
For windows u can use CodeBlocks I believe it uses gcc and its pretty user friendly
对于 Windows,你可以使用 CodeBlocks 我相信它使用 gcc 并且它非常用户友好
回答by Nathan Osman
回答by Ben Voigt
The key to writing portable C++ code is:
编写可移植 C++ 代码的关键是:
- Use a cross-platform version control system (subversion is a great choice), because this makes it easier to
- Compile and test your code on other platforms early and often
- 使用跨平台的版本控制系统(subversion 是一个不错的选择),因为这样更容易
- 尽早并经常在其他平台上编译和测试您的代码