Is the LLVM 5.0 compiler equivalent to the GCC compiler? - c++

I have to write my projects for class in ISO C++ or C++/CLI and while the professor explains how to accomplish this in Windows, it is very difficult to know how to setup the equivalent on my Mac. I am currently running xCode 5.0.2 and it seems to compile the sample applications with no problem using the LLVM 5.0 compiler. I've read that Apple no longer supports GCC compiler, so my question is are the two compilers equivalent? Will code that runs in GCC compiler also work in the LLVM 5.0 compiler?

There is no LLVM 5.0. The LLVM project is currently at version 3.4. The Apple LLVM/Clang variant shipped with XCode 5 may carry a version number that corresponds to the XCode version, but that is mildly misleading.
That said, yes, most stuff that works with GCC 4.2 (the last one that Apple shipped) will work just fine with LLVM/Clang.
C++/CLI, on the other hand, is a Microsoft-proprietary thing and you will not be able to use it on a Mac no matter what, and neither GCC nor Clang support it.

Will code that runs in GCC compiler also work in the LLVM 5.0
compiler?
If by "runs" you mean "compiles," then yes, assuming your code is Standard-compliant.
Weather or not your code is Standard-complliant depends, in part, on how well your professor is doing his job.

Mostly. Being compatible with GCC is one of Clang's primary goals (see http://clang.llvm.org/features.html#gcccompat ). That said, you can install gcc via MacPorts, http://www.macports.org/ if you really need it.

Related

Clang built on GCC

I was searching online to see if clang supported reproducible builds. I read that GCC guaranteed reproducible builds using the -frandom-seed flag. I wanted to know if clang supports that flag and I could not find anything regarding that.I then came here which had a statement such as:
...two consecutive builds of (GCC-built) Clang
My question is what is GCC built clang ? I am currently aware of only 2 compilers (Microsoft , GCC (Coudl be Cygwin/Mingw flavor) ) and the third one was suppose to be clang. My question is what does clang (GCC built) mean ? Built from source ? I would like to think that clang is a totally different compiler from GCC and Windows. Also this documentation here states
Clang has experimental support for targeting “Cygming” (Cygwin /
MinGW) platforms.
What does that mean ? Does clang mean that it uses Mingw GCC as a compiler ? What does targeting mean here ?
To my mind, this phrase means clang was built from source using GCC as a compiler. Then, clang is a compiler, so it can't use GCC as a compiler.
Compilers are written in programming languages to be able to compile code written in a programming language. This means, a compiler can compile a compiler or even itself.
If you don't know is feature X supported in product Y, please, read the docs on product Y. If this feature isn't mentioned, it's not supported and vice versa.

How can I write cross-platform c++ programs on my mac?

My university professor has given a requirement for us in his c++ class: We must write our programs using the gnu C++ compiler (GCC). I understand that after installing xcode, I get an apple version of gcc. However, this is not fully cross compatible as I understand. So I have tried to install the gnu gcc compiler by using mac ports, but I have been unsuccessful. After doing:
port install gcc47
When I go to the terminal and run:
gcc47 -v
I get "command not found"
When I run:
gcc -v
I get:
gcc version 4.2.1 (Apple Inc. build 5666) (dot 3)
Showing that I am still using apple's version. The part I am not understanding is:
How do I install gcc (the gnu version, not apple's version)
How do I use it with an ide, such as eclipse?
The version of GCC you use (Apple or gnu native) should be irrelevant for you to proceed.
Writing portable C++ has nothing to do with the compiler--outside of ensuring your compiler does it's best to adhere to the C++ standard. Luckily enough, GCC is one of the best C++ compilers out there.
You're not looking to do cross-platform C++ per-se, because true portable C++ is somewhat of a pain to write given the various state of C++ compilers for various systems (for example the CC on VAX/VMS doesn't support templates...). I suspect what you want to do is ensure the code you write on your mac, can be compiled by your prof. As long as GCC can handle it on your mac, it should be fine.
So to your specific questions:
Your first question is unnecessary, as you can use apple's supplied g++ to compile your code.
For your second question, I would highly recommend against using an IDE while trying to learn. IDE's offer some really great time saving features, but they hide some important aspects, that I believe are worth struggling with early in your learning process, and which will help strengthen your C++ skills. And while things have certainly have gotten better, some IDE's were notorious for creating non-portable C++ (ie using void main()).
If you are still set on using Eclipse, or XCode, since it doesn't matter which GCC installation you use, the default setup should work just fine.
I've run into troubles installing gcc47 via ports in the past, but gcc46 went as expected. You may also want to install gcc_select.
From there, you can use gcc_select, or specify the path explicitly in Eclipse's toolchain editor.
Other notes:
If you don't need C++11 features, then Apple's GCC 4.2.1 should work fine. Perhaps you can detail why you can't use it. Basically, Apple's added some extensions to the toolchain in some cases (marked APPLE_ONLY), and you have good control of what options are enabled/disabled.
Recent versions of Clang which ship with Xcode handle C++ well (including some support for C++11). There are some advanced things in GCC that I miss when using Clang, but Clang's current C++ support is really quite good.

LLVM compiler for production code?

I have a question concerning the LLVM compiler:
I would like to use it to compile my Objective-C source code for Mac and iOS and from their release notes it seems that LLVM is stable enough for using this.
Having made good experiences with the LLVM I would also like to use it to compile C++ or Objective-C++. However it is not clear to me if I should still use the hybrid LLVM-GCC compiler (the GCC parser and the LLVM code generator) or the pure LLVM compiler.
I am also unsure about the new C++ standard library and if I should use it and how I would make the transition from GNU's libstdc++.
The Questions
Which compiler would one use today to generate fast production quality code from C++: the LLVM-GCC hybrid compiler or pure LLVM?
Should one migrate the C++ standard library from GNU's libstdc++ to the new libc++ library created by the LLVM project?
Any comments and hints are appreciated.
Several questions asked here, I'll try to answer all of them.
There is no "pure LLVM compiler". LLVM is a set of libraries which do code optimization and code generation . There are several C/C++ frontends which can be hooked to LLVM. Among them are clang and llvm-gcc. See http://llvm.org/ for more information about various components of LLVM Compiler Infrastructure. As written at http://llvm.org/docs/ReleaseNotes.html, llvm-gcc is EOL since LLVM 2.9 release, so you'd better use clang, because it will certainly be developed and maintained in the future.
libc++ is still in development, so for production you should use vendor-provided C++ (libstdc++ in your case).
Remember, all this stuff is changing, so benchmarks gets easily outdated.
I've found following report interesting, not only as a kind of benchmark, but it seems showing some LLVM vs GCC compiler differences :
Clang/LLVM Maturity Evaluation Report by Dominic Fandrey

Can I upgrade Xcode to support a newer version of GCC to learn C++0x?

I would like to jump in learn C++0x, which has matured to a level I'm happy with.
Xcode on Snow Leopard 10.6 is currently at GCC 4.2.1, and the new features I'd like to try, like std::shared_ptr, lambdas, auto, null pointer constant, unicode string literals, and other bits and pieces, require at least 4.3 (I believe).
Ideally I'd use Xcode but I'm not even sure if you can manually upgrade the compiler for Xcode. Is this possible?
Otherwise, what is the best way to install a different version of GCC that doesn't interfere with the rest of the system?
I ended up downloading the latest Intel Compiler for Mac trial, and it does what I need. It's a good way to test the waters without messing with your system.
http://software.intel.com/en-us/intel-compilers/
You may want to look at LLVM and Clang and see if those can accomplish what you're after, if you want to use XCode. Apple has been making a shift away from GCC and towards LLVM/Clang due to licensing reasons.

gcc version 4.1.2 in mac os x

I am taking a programming class and we are required to use the gcc 4.1.2 compiler to compile our c++ projects. I will be creating my projects in xcode and can't find how to set that compiler. I went to the get info window on the project and hit the drop down under Compiler Version, however I do not have 4.1.2 on the list. It seems that this compiler is not installed on my computer. Does anybody know where I can download it and how I can set it as my system default gcc compiler for the term?
You can probably get away with using whatever version of GCC is on your Mac, and doing a final compile on the university machines as a check. In general, the user visible changes using a later version is stricter syntax checking, so you might do something on the Mac that won't pass a newer compiler, but that generally isn't too common. I haven't had to change more than a few lines on our 50k line codebase.
With the current developer tools, only gcc 4.0 and 4.2 are available. You could probably get gcc 4.1.2 via MacPorts, however, I'm not sure whether you can integrate it into XCode.
Before you try this, you should maybe first check with the class instructor whether it is really necessary to use exactly 4.1.2, or if it is OK to use 4.0 resp. 4.2 instead.