Clang built on GCC - c++

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.

Related

Do any compilers currently support C++20?

I purchased a book recently entitled beginning C++20. I was looking to begin learning c++ though I now realize that I can't find a compiler that can run the code in the book as I get an error since the compiler I'm using (xcode) does not support c++ 20. I'm wondering if there are any compilers that I can run on my mac that support c++20.
gcc version 8 and up supports some of C++20; you can try using that.
It should also be noted that Xcode isn't a compiler, but instead an IDE that should be using clang as the actual compiler. Clang also currently has support for some of the C++ 20 features. To use them the -std=c++20 flag will still be needed.
Here can you find the currently implemented feature support of the GCC compiler of the C++20 specification:
GCC Link
But you need to enable it in your console command or add this to your toolchain: "-std=c++20"

Many questions about the various C++ compilers available to me on OS X

I am having trouble understanding the different compilers that are available to me.
I mainly use Xcode for writing and compiling, and in Xcode's preferences, there are all of these options for C++ compilation:
C++ Language Dialect:
C++98[-std=c++98] through C++14[-std=c++14]
GNU++98[-std=gnu++98] through GNU++14[-std=gnu++14]
C++ Standard Library:
libstdc++ (GNU C++ standard library)
libc++ (LLVM C++ standard library with C++11 support)
Can someone explain what exactly all of that ^ is?
I understand that (and correct me if I'm wrong), that apple no longer distributes GCC with Xcode and use Clang instead?
If that were the case, then why does Xcode have the option for GNU C++ standard library? Doesn't GNU make GCC?
What compiler is invoked when I run C++ code in my local terminal with g++ filename.cpp?
Is there any way to make sure that this g++ "compiler" is up to date?
What's the difference between compiling with g++ in the terminal and using Xcode?
Also, what would be the difference if I tried running C++ programs with Clang?
My class requires us to test our programs on the department's server's compiler via ssh from my terminal. The server is a Unix machine and I know that its compiler is GNU's GCC compiler and we also access it using g++. Does this mean that the local g++ in my terminal is also GCC?
edit: Grammar
1.
C++ language dialect
C++98[-std=c++98] through C++14[-std=c++14]
GNU++98[-std=gnu++98] through GNU++14[-std=gnu++14]
The C++ language has evolved over time. These are the various versions of the language that are available to you. If you have to be compatible with something old, you might be forced to use an old one. Otherwise you'd probably want ot use the newest available, which is c++14 in the list above. 14 stands for 2014, 98 for 1998 - it is supposed to represent the year that version of the standard was blessed.
In addition to standard C++ there are non-standard extensions. Gnu is a compiler "manufacturer", the "GNU" above is the non-stanadard extensions as specified by GNU for a particular documented version.
C++ Standard Library:
libstdc++ (GNU C++ standard library)
libc++ (LLVM C++ standard library with C++11 support)
In addition to the base language, the standard library is also a part of the standard. These are two different implementations of the standard library. The first is by GNU, the second by llvm. llvm are a different compiler manufacturer.
On osx you'd probably use libc++ as I believe the llvm compiler (clang++) is now standard there. The llvm compiler will support the gnu extensions if you need them. You probably don't. Just use the latest version of whatever is default.
Yes
two different pieces, the compiler and the standard library. You can use clang++ with libstd++
g++ -v will tell you
not really. Update xcode to the newest or start looking at homebrew or ports to get the latest and greatest they package of whatever compiler you like.
Probably the same compiler, you can set it either to point at any compiler you have installed. So what each points at is your choice.
both g++ and clang++ are standards compliant. You're unlikely to notice much difference. They will complile the same source files into equivalent binaries.
run g++ -v in any terminal to see exactly what it is.

Is the LLVM 5.0 compiler equivalent to the GCC compiler?

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.

Run C++ Code Online?

Is there a website I can go to to run C++ code online? I have seen a few compilers, but is there one that can also receive input from cin? I want one that can basically host a C++ .exe online, and even more preferable is if it is like the VC++ platform.
You may want to give rextester a try. Currently g++ 4.7.2 with boost libraries and ability to supply compiler args.
Edit
Visual C++ is also supported now.
http://ideone.com/ Can compile several languages, and supports stdin
Yes, Ideone can do that. It's possible to specify stdin there.
Edit: Microsoft's online compiler seems to no longer be active :(
Microsoft research have made an online version of Visual C++ here: http://webcompiler.cloudapp.net/.
It (currently?) only compiles the code and does not run it so you won't be able to check cin though :(
Running code is now supported.
Currently the best online tools seem to be
Special Online Compilers
https://cppinsights.io shows, how C++ introduces conversions, etc. and interprets the source code (current clang based)
https://godbolt.org compare C++ compilers, show disassembly, run (many current compilers including Microsoft VCC and embedded compilers)
http://quick-bench.com create and compare benchmarks (current g++ and clang)
https://www.onlinegdb.com, includes gdb debugger (g++ 7.4.0)
Online Compilers that let you set compile flags
https://wandbox.org (current g++ and clang)
http://coliru.stacked-crooked.com (g++ 9.2.0)
https://repl.it/languages/cpp11 (clang 7.0.0)
https://www.tutorialspoint.com/compile_cpp11_online.php = codingground (g++ 7.1.1)
https://tio.run/#cpp-clang (g++ 8.3.1 and clang 7.0.1)
https://rextester.com/l/cpp_online_compiler_gcc (g++ 7.4.0, clang 6.0.0, VS C++ 2015 Update 1)
Online Compilers that do not let you set compile flags
https://www.jdoodle.com (g++ 9.2.0)
https://www.codechef.com/ide (g++ 9.1.0)
https://ideone.com (g++ 8.3.0 and clang 8.0.0)
https://paiza.io (clang 8.0.0)
https://www.codiva.io/c (clang 7.1.0)
https://code.labstack.com/cpp (g++ 8.3.0)
All listed compilers support C++17 code
Perhaps the following site is what you're aiming for: http://codepad.org/
There is Wandbox.org, which offers GCC and Clang to its latest versions (as of Nov 2018). It has stdin.
I wouldn't say it's a VC++ platform though.
TutorialsPoint's C++ Coding Ground lets you save and compile multiple source files at a time, which can be useful at times, and gives you a GNU bash console to play around with. It's not as convenient for sharing code as sites like Ideone, however.
[Note: While it only has links to C++, C++0x, and C++11 environments, you can compile code for C++14 by specifying the compiler option -std=c++1y. I'm not sure if it has any experimental C++17 support, however.]
repl.it can compile, run, and execute C++ and C++11. It's also interactive and you can ask for user input in realtime.

what c++ norme i'm currently using? [duplicate]

This question already has answers here:
How to determine the version of the C++ standard used by the compiler?
(9 answers)
Closed 6 years ago.
Recently I had faced compiling errors in a c++ code I wrote so I've been asked if I was using a C++11 compiler, but honestly I don't know how to check on my compiler version ! so any idea how to figure this out ??
Btw I'm using codeblocks as an IDE which includes the GCC compiler and GDB debugger from MinGW. also if I'm compiling my c++ code under Linux what command should I run to know my compiler version ?
That can be a tricky question. C++11 refers to a version of the
standard, not to a version of the compiler. Different compilers, and
different versions of any given compiler, will typically implement a mix
of versions of the standard, at least for recent versions. More or
less, because any implementation of C++11 will be fairly new, and thus
probably fairly buggy.
Most compilers have options to output the version; many will output it
systematically in verbose mode. For g++, try g++ --version. Recent
versions of g++ do have some support for C++11, but you have to activate
it with -std=c++0x (rather than the usual -std=c++03 or
-std=c++98). As the name (c++0x, rather than c++11) indicates, it
is not truly C++11; it is an implementation of some (most?) of the
major new features, in a preliminary version based on various working
papers, and not the final standard.
(FWIW: I don't think any compiler fully implements all of C++11, but I'd
love to be proven wrong.)
You can find out your compiler version like this:
g++ --version
That doesn't tell you if you are using c++11. To use c++11 features, you would have to call the compiler with thr -std=c++0x flag:
g++ -std=c++0x ....
Bear in mind that gcc doesn't implement 100% of c++11 yet, and how much it implements depends on the version. See here for a table of supported features.
EDIT: strictly speaking, if you are using GCC you cannot be using a fully compliant c++11 compiler due to the missing features. But versions 4.6.1 onwards cover a great deal of the standard.
If you're in linux, checking the version is easy.
> gcc --version
Will tell you the version you have. Note that GCC C++11 support is incomplete still, you can find the details here: http://gcc.gnu.org/projects/cxx0x.html
I've used a few C++11 features myself, namely initializer lists, and the nullptr constant. I'm using GCC 4.6 and it's working fine.
edit: And yes, as #jaunchopanza said, you'll need the -std=c++0x compiler flag to make it work. If you're using Code::Blocks, just right-click on your project, choose Build options..., and check the item that says Have g++ follow the coming C++0x ISO C++ language standard [-std=c++0x]