How to switch between gcc versions correctly?

I want to play with C ++ 2011, so I need an unreleased gcc 4.7. I was able to successfully get the svn trunk and compile it.

I want to keep gcc default on my system for security, so I configured gcc4.7 with --prefix and installed it in a non-standard location.

Now how do I enable gcc 4.7 by default gcc of my system?

I have already changed the CC and CXX variables, I updated my PATH to point to gcc 4.7 bin first. When I type gcc -version, I get 4.7 OK.

But gcc is more than just an executable. There are many executables in gcc install dir. There is also default includes std lib C ++.

So far, every blog post / SO question I have found on this question only talks about gcc and g ++ executables.

Can someone give me a list of the changes I need to make for the environment in order to make full use of gcc 4.7? update LD_LIBRARY_PATH? How to give preference to the gcc 4.7 system? Are there any other questions?

Thanks in advance.

+4
source share
3 answers

The simplest answer: nothing; it just works. :)

GCC finds what it needs first of all with respect to itself, the second in the β€œprefix” with which it was configured, and, finally, in standard places. Thus, it is completely safe to move it wherever you are, as long as you move it all, but be careful that the rebound behavior can hide the violation if the installation is incomplete.

+1
source

I would think that g ++ is pretty much confused about things using C ++, since the C library is messed up with the system! Any layout changes in C ++ library classes will cause incompatibility with other C ++ programs or libraries. Thus, I would not replace the C ++ system compiler or, more importantly, its standard C ++ library in general (unless, perhaps, the compiler provider claims that they have maintained binary compatibility with the version you are replacing).

To play or even use a different version of g ++, using the prefix approach works fine. All compiler-specific tools are implicitly called from g ++ using the corresponding version, and tools like ar, ld, ranblib, etc. In any case, it does not depend on the version of the compiler. Important components that use internally are the standard library (both headers and the library) and the preprocessor. When invoking the g ++ version, it determines which one is really needed.

By the way, when you want to play with C ++ 2011, you can also take a look at clang.

+2
source

See GCC Configuration Documents . I use software suffixes to distinguish between different versions of GCC. To do this, add, for example, --progam-suffix=-4.7 to your ./configure call.

0
source

Source: https://habr.com/ru/post/1388480/


All Articles