install multiple versions of g++(or gcc) [closed] - c++

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I was wondering if it is possible to install multiple versions of g++ on the same machine without any problem.
I use the almost current gcc for my work(4.6.1). Now for my studies, my teacher has given us an incomplete project to complete and he says we should install gcc 3.4.3 .
please note that I have already read this : Is it possible to install 2 different versions of GCC at the same time? but I don't know what PATH I should set.
Moreover, I would like to use eclipse for both version. So I may need some guidance for that settings too.
Thank you very much

In bash you could do two scripts like this:
first one:
export PATH=/path/to/your/3.4.3/bin:$PATH
eclipse&
and
export PATH=/path/to/your/4.6.1/bin:$PATH
eclipse&
By running one of those, eclipse should use first gcc it finds in your path. Also your default gcc should still be primary, if you don't run any scripts.
BTW:
You can probably strike a deal with your professor on what c++ standard he wants you to use (and what libraries), not what outdated version of compiler you should use to compile your code.

If you are using some Linux distribution, you can install several versions of GCC; for instance on Debian or Ubuntu you could install both gcc-4.6 and gcc-4.7 (the exact versions available depend upon the actual distribution).
Notice that GCC 3.4.3 is a very ancient version of the compiler (it has been released in november 2004). You may have trouble to install such an ancient version of GCC on your machine. Notice also that recent GCC (last version is 4.7) gives much better warnings, optimizations, and standard conformance than ancient version.
Of course, you don't need eclipse to use GCC. You could use some plain editor like gedit or emacs, and compile either on a command line (if you have only one file) or using a builder like make.
I would not bother installing GCC 3.4.3 on a recent machine (i.e. any Linux distribution from the last few years), because you could spend more than a week in installing such an old thing, and still fail. I would use the latest GCC available on that machine, always compile with -Wall -g and ask (or tell) my teacher about it.
Learn also to use the gdb debugger, and some version control like git.
The hints I gave here are probably relevant to you.

Related

Choosing a default gcc/g++ compiler

Im running Matlab on linux (Elementary OS)
The problem im facing is that Matlab isnt compatible with the gcc compiler higher than 4.9.
Same question as: https://www.mathworks.com/matlabcentral/answers/348906-downgrading-gcc-g-for-use-with-mex
When I use "sudo apt get install gcc" 5.4 is automatically installed. When I remove 5.4, Matlab will not recognize 4.9 which I've installed. How do I get Matlab to recognize gcc/g++ 4.9 as my compiler?
I've also followed this but it didnt resolve the problem:
https://www.mathworks.com/matlabcentral/answers/137228-setup-mex-compiler-for-r2014a-for-linux#answer_263109
Any help would be greatly appreciated.
When I remove 5.4, Matlab will not recognize 4.9 which I've installed. How do I get Matlab to recognize gcc/g++ 4.9 as my compiler?
I use Ubuntu (from which you OS is derived) and have had a similar issue. Basically, you can use update-alternative to switch between gcc versions on your choice. Here is a link that explains how to do it.
Here is the documentation on update-alternative, if you need more in-depth knowledge of its functionalities.
Note that uninstalling the default gcc for your distro (5.4 in your case) is no longer required with this solution: you can switch back to it for you development when not using Matlab. You can even install more than two versions of gcc if needed.
Hope this solves your issue.
There is no reason to downgrade GCC for MATLAB.
The reason you run into issues on Linux is because MATLAB installs its own copies of the GCC libraries. If your MEX-files expect newer libraries, they'll fail. You can delete the GCC libraries that come with MATLAB, and it will use the newer ones on your system.
The libraries are at $(MATLABROOT)/sys/os/glnx86 for 32-bit MATLAB, and $(MATLABROOT)/sys/os/glnxa64 for 64-bit MATLAB. $(MATLABROOT) is the installation root for MATLAB.
The files in question are libgcc_s.so*, libstdc++.so* and libg2c.so* (or at least they used to be called like this, I don't have a Linux MATLAB installation here to double-check).
This trick worked for MATLAB 7.0, and still worked a month ago when I suggested this to a colleague.
I do recommend that you rename or move the files, so you can replace them if things go sour.
You will need to restart MATLAB after this change, of course.

Undefined function for input arguments of type 'double' [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I downloaded the MATLAB code from here http://cazencott.info/dotclear/public/code/scones.zip. When I run 'demo', it says "Undefined function 'maxflowmex' for input arguments of type 'double'". In fact there is only a c++ file "maxflowmex.cpp" in the folder (already added to path). Whether it needs a "maxflowmex.m" instead of "maxflowmex.cpp" to run properly? Or some other methods to call "maxflowmex.cpp"? Or I need to compile something?
I just took a look at the zip file. There are MEX wrappers in the maxflow directory that are written where MATLAB calls these functions which are written in C, but are runnable in MATLAB. These MEX wrappers need to be compiled using a compiler that is compatible for your operating system before you run them.
However, there are pre-compiled binaries, but I only see 64-bit binaries for Linux and Mac OS and I don't see Windows binaries. Because you can't run them, you are most likely running a 32-bit operating system or Windows. I suspect you are running either Windows or 32-bit Linux, as Mac OS by default ships out as 64-bit.
There is a make.m script that you need to run so that you can compile the maxflow library for your machine. Once you compile the library, running demo.m should be successful.
Before you do that, you need to make sure you set up mex by doing mex -setup in the command window, then choose the right compiler. Once you do this, run make.m that's inside the maxflow directory.
If you don't have a compiler, if you're using Linux, doing an apt-get on the gcc packages should be good enough, so:
sudo apt-get update
sudo apt-get install gcc-4.6-base g++-4.6 cpp-4.6 libgomp1 libquadmath0 libc6-dev
If you are using Windows, then the supported compiler that you need will depend on what version of MATLAB you are using. I'm assuming you are using the latest one, and so downloading the latest version of Visual Studio Express as well as the SDK should be sufficient.
http://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx
http://www.microsoft.com/en-us/download/details.aspx?id=40758

Ubuntu to RHEL C++ cross-compilation (64bits)

Not exactly sure where this question belongs, let me know if I should move it.
Here is the issue; over the past years I have a put together a relatively large personal codebase in C++11 that I'm using for work, but my workplace runs supposedly the latest version of RHEL on their cluster, which runs gcc 4.4.7, which supports C++11 only partially.
I have battled to get a decent compiler installed, but apparently there is no easy way of making this happen, so instead I am wondering whether it would be possible to cross-compile C++11 sources on my own desktop, and export the executable on the cluster at my workplace. I just don't know where to start in order to do that:
Is it possible (and how) to cross-compile C++11 sources from Ubuntu to RHEL?
Since I am at it, is it possible to rebuild gcc 4.8 or a suitable libstdc++ (or libc++) entirely from Ubuntu to an rpm package compatible with RHEL?
(Note: I would preferably use clang (3.4) to compile on my desktop, but gcc (4.8) would be fine too.)

Compile C++11 code on mac?

I'm new to C++11. I've tried:
clang++ -std=c++11 -stdlib=libc++ *.cc
It works, but my questions is:
Is there anyway to set these flag as default for clang++?
How to update g++ 4.2 to a version that supports C++11?
Which way do you think it's the best to compile C++11 code on mac?
Thanks.
Brett has described how to install GCC it with MacPorts. Here’s how to do it with Homebrew, which styles itself (rightfully!) as a modern replacement of MacPorts:
brew tap homebrew/versions
brew install --enable-cxx gcc48
As far as I know the easiest way to install the most recent Clang is by downloading the compiled version linked in dsign’s answer – and, as Brett mentioned, since Apple uses clang internally it’s not advised to tinker with that installation – just put yours somewhere else.
Concerning what the “best” compiler is there are two things to consider in addition to what Brett has already said:
GCC is much older and more mature than Clang. Internal compiler errors do happen occasionally in Clang. That said, it’s maturing rapidly because it’s being pushed by several companies.
Clang is feature complete for C++11, GCC 4.8 is not. One very obvious example of this is the fact that GCC 4.8 still has no working <regex> implementation, which is a shame.
Outside of an IDE (e.g., in shell), I normally have the variable CXX set to: "clang -std=c++11 -stdlib=libc++" in .profile / .tcshrc / etc., since this is picked up by most configure scripts too. On the cmd line I might use: $CXX -c foo.cc
MacPorts gcc-4.8.1 works well: "[sudo] port install gcc48 [-universal]"
"[sudo] port select --set gcc gcc48" will make this the default gcc, g++, etc.
Don't attempt to update or modify the system tools, like the old gcc-4.2 / llvm hybrid that comes with Xcode.
I don't know what you mean by 'best' way in the 3rd part of your question, but with Apple's support (they employ the primary author of LLVM), and other projects like FreeBSD behind it, clang will only continue to improve. It's already much faster than gcc, has far better error messages / diagnostics (especially for C++ and templates), and a modular architecture. For OS X, it's the clear choice.
Answers:
I don't think so
You install another g++ version alongside 4.2, it is bad karma to remove the one that comes with the system. To install a new one, check this
Same goes for clang. You can download it here.
In general, I totally recommend that you get better g++ compilers, 4.2 is quite old and its code quality is not as good. And using c++ 11 is totally worth it.
Do it all in Xcode's build settings like most Apple developers. Xcode simplifies life in many ways.

./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.