GNU gcc and g++ - c++

Are the gcc and g++ compilers installed on a MAC OS X machine different from the ones on Ubuntu (Linux) GNU gcc and g++ compilers?
I am using Eclipse to develop a C++ program and there is toolchain section where it says MacOSX GCC and I was wondering if I need to install another compiler so that the executable would also run on Linux machines.
I am a bit new to the technical details of C++ development so I am sorry if this question does not make sense.

It it very unlikely that binary will execute on both Mac and on Linux. If is pretty likely that a binary will not execute between different distro's of Linux. You can either compile you binary for each OS. Or you can distribute the source code for you application and let you users compile it themselves.
Different versions of libstdc++.so are likely distributed with different OS's and this will cause you problems. A solution that partly works is to statically compile your binary so you are not depending on the target systems installed version of libraries.

MacOS is not Linux, it might have a bit in common with BSD, but definitely not Linux. They do, or can, use different configurations of the same compiler, but the programs are not compatible.
The only way you're going to run the same program on both is if you have something like Wine to provide a compatibility layer.

Related

How to compile a program on bleeding edge linux to run on old linux

I use install Arch Linux with duel booted Linux Mint 18.1 .In my college we have lubuntu 16.04 and Ubuntu 14.04 installed. I have also enabled testing repos in arch Linux so I get newer packages, thus due to this when I compile any C++ program on Arch it won't run on Linux Mint due to version of shared libraries don't match in mint.
like libMango.so.64 is in arch and libMango.so.60 is on mint. How can I overcome with this ?
so I am asking for how can I compile any C/C++ with newer compiler and shared libraries to to run fine with old shared libraries ? Just like I compile 32 bit programs on 64 bit machine with -m32 flag , is there flag for old shared libraries too ?
I am using gcc 8.1.
how can I compile any C/C++ with newer compiler and shared libraries to to run fine with old shared libraries ?
You cannot do that reliably if the API (or even the ABI, including size and alignment of internal structures, offsets of fields, vtables organization) of those libraries have changed incompatibly.
In general, you'll better recompile your source code on the other computer (and your college might forbid that, if that source is unrelated to your education). BTW, if your source code sits in some git repository (e.g. github if it is open source) transferring on multiple computers is very easy.
Some very few libraries make genuine (and documented) efforts on being compatible with other versions of them in binary form (e.g. at the ABI level), but this is not usual. The Unix and free software tradition is to care about source level compatibility. And the POSIX standard cares only about source compatibility.
You might consider using some chroot-ed environment (see chroot(2) and path_resolution(7) & credentials(7)) to have the essential parts of your older distribution on your newer one. Details are distribution specific (on Debian & Ubuntu, see also schroot and debootstrap). You could also consider running a full distribution in some VM, or using containers à la Docker.
And you might try to link (locally) your executable statically, so compile and link with g++ -static

whats the difference between mingw and mingw64 [duplicate]

What are the differences between MinGW, MinGW-w64 and MinGW-builds?
And which one should I use to compile c++ 11 source code with the Eclipse IDE on a Windows 8 machine?
MinGW is a GCC-port for Windows. Not all of the Windows API is supported (but for many programs the supported stuff is sufficient) and it´s only for 32bit-Programs (which often can run on 64bit-Windows too, but some can´t, and you can´t compile them as 64bit).
MinGW-w64 is a improved version which supports both 32bit and 64bit, and some more of the WinAPI (still not all, because thats much work, but more than MinGW).
MinGW-w64 only provides their source code, but no binaries to "just use" the compiler.
MinGW-builds is a somewhat separate project to provide binaries in the most useful configurations. To get a specialized build of MinGW-w64, manual compiling is still possible.
Using the MinGW-builds self-installer is the easiest way, if nothing unusual is needed. Also see here for help with the self-installer.
Mingw compiles your code to Windows binaries that run under Windows.
Windows subsystem for Linux (WSL) makes Linux binaries. You can install other Linux programs under WSL, except if you need a graphical interface. You can access the Windows filesystem from WSL, but not vice versa.
Cygwin makes Windows binaries that can run under Windows outside the Cygwin shell, as long as you have the Cygwin DLL. This gives a Linux-like environment that is fully compatible with Windows.

Relationship between gcc, g++, cygwin, and wingw?

I know for my class, I had to install cygwin to get my Netbeans IDE running, but I see options during setup for both g++ and gcc and I am not sure if they are the same thing or not, and where does wingw? is it another compiler, and if so why choose on over the other?
g++ and gcc are the gnu C++ and C compiler respectively. They're really the same compiler with different flags though.
MinGW is "Minimalist Gnu for Windows". It's a port of the gnu compiler to run on Windows.
Cygwin is another port of the gnu compiler (and various other utilities) to Windows. More accurately (IMO, anyway), it's leaving the compiler/programs running on POSIX, and porting a POSIX layer to run on Windows.
As to choosing between them: if you're running Linux, you probably want ot just get a package of gcc/g++ for the distro you're using.
If you're running Windows, it'll depend on your intent. Cygwin works well for porting existing Linux/POSIX code to Windows. If, however, you plan to write code, and just want a compiler, I'd go for MinGW instead.
One other note: the MinGW at MinGW.org hasn't been updated in years. If you decide to go with MinGW, I'd advise getting it from nuwen.net instead (it's updated quite regularly).
gcc will compile: .c/.cpp files as C and C++ respectively.
g++ will compile: .c/.cpp files but they will all be treated as
C++ files.
Also if you use g++ to link the object files it automatically
links in the std C++ libraries (gcc does not do this).
gcc compiling C files has less predefined macros.
For wingw, did you mean mingw? Because MinGW is for compatibility with Windows. MinGW uses GCC/G++, and MinGW is not a compiler, it's basically a stripped version of Cygwin that uses MS libs wherever possible.
Depends upon what you are building;
gcc is for C programs.
g++ is for C++ programs.
I've not heard of wingw.

How to compile C++ programs in codeblocks for 32bit computers with the dual targets MinGw compiler [duplicate]

I've downloaded MinGW with mingw-get-inst, and now I've noticed that it cannot compile for x64.
So is there any 32-bit binary version of the MinGW compiler that can both compile for 32-bit Windows and also for 64-bit Windows?
I don't want a 64-bit version that can generate 32-bit code, since I want the compiler to also run on 32-bit Windows, and I'm only looking for precompiled binaries here, not source files, since I've spent countless hours compiling GCC and failing, and I've given up for a while. :(
AFAIK mingw targets either 32 bit windows or 64 bit windows, but not both, so you would need two installs. And the latter is still considered beta.
For you what you want is either mingw-w64-bin_i686-mingw or mingw-w64-bin_i686-cygwin if you want to compile for windows 64. For win32, just use what you get with mingw-get-inst.
See http://sourceforge.net/apps/trac/mingw-w64/wiki/download%20filename%20structure for an explanation of file names.
I realize this is an old question. However it's linked to the many times the question has been repeated.
I have found, after lots of research that, by now, years later, both compilers are commonly installed by default when installing mingw from your repository (i.e. synaptic).
You can check and verify by running Linux's locate command:
$ locate -r "mingw32.*[cg]++$"
On my Ubuntu (13.10) install I have by default the following compilers to choose from... found by issuing the locate command.
/usr/bin/amd64-mingw32msvc-c++
/usr/bin/amd64-mingw32msvc-g++
/usr/bin/i586-mingw32msvc-c++
/usr/bin/i586-mingw32msvc-g++
/usr/bin/i686-w64-mingw32-c++
/usr/bin/i686-w64-mingw32-g++
/usr/bin/x86_64-w64-mingw32-c++
/usr/bin/x86_64-w64-mingw32-g++
Finally, the least you'd have to do on many systems is run:
$ sudo apt-get install gcc-mingw32
I hope the many links to this page can spare a lot of programmers some search time.
for you situation, you can download multilib (include lib32 and lib64) version for Mingw64:
Multilib Toolchains(Targetting Win32 and Win64)
By default it is compiled for 64bit.You can add -m32 flag to compile for 32bit program.
But sadly,no gdb provided,you ought to add it manually.
Because according to mingw-64's todo list, gcc multilib version is done,but gdb
multilib version is still in progress,you could use it maybe in the future.
Support of multilib build in configure and in gcc. Parts are already present in gcc's 4.5 version by using target triplet -w64-mingw32.
gdb -- Native support is present, but some features like multi-arch support (debugging 32-bit and 64-bit by one gdb) are still missing features.
mingw-64-todo-list

./configure make make install on Windows with icc

I recently switched back to Windows7 (x64) because of perfomance issues with my graphics card on linux but i miss the abilty to easily compile open source software on Windows. I have a copy of the intel c compiler which is somewhat better than the gnu c compiler and i would like to use it to compile software written for linux.
I've already installed cygwin and managed to compile something. The 'make-install' didn't work though but that's another issue. Now my question is, how can i tell 'make' to use the windows intel compiler?
Most of the configure scripts you'll find in OSS have probably been created by the Autotools. Those should, basically, support the icc. To use it, although you may have GCC installed side-by-side, it would be necessary to set the environment variable CC to the (cygwin) path to Intel's C compiler and CXX to Intel's C++ compiler prior to running configure.
You may run into trouble with software packages that unconditionally set compiler flags that only GCC understands. I have heard, though, that, by now, icc actually implements most of these.
Update
Something similar has been asked before.