How to reinstall gcc

How to reinstall gcc

Installing GCC

This page is intended to offer guidance to avoid some common problems when installing GCC, the official installation docs are in the Installing GCC section of the main GCC documentation. N.B. those installation docs refer to the development trunk, the installation instructions for released versions are included in the release sources.

For most people the easiest way to install GCC is to install a package made for your operating system. The GCC project does not provide pre-built binaries of GCC, only source code, but all GNU/Linux distributions include packages for GCC. The BSD-based systems include GCC in their ports collections. For other operating systems the Installing GCC: Binaries page lists some third-party sources of GCC binaries.

If you cannot find suitable binaries for your system, or you need a newer version than is available, you will need to build GCC from source in order to install it.

Building GCC

Many people rush into trying to build GCC without reading the installation docs properly and make one or more of these common mistakes:

    if GCC links dynamically to the GMP, MPFR or MPC support libraries then the relevant shared libraries must be in the dynamic linker’s path, both when building gcc and when using the installed compiler (this is also a FAQ)

    Support libraries

    See Installing GCC: Prequisites for the software required to build GCC. If you do not have the GMP, MPFR and MPC support libraries already installed as part of your operating system then there are two simple ways to proceed, and one difficult, error-prone way. For some reason most people choose the difficult way. The easy ways are:

      If it provides sufficiently recent versions, use your OS package management system to install the support libraries in standard system locations. For Debian-based systems, including Ubuntu, you should install the packages libgmp-dev, libmpfr-dev and libmpc-dev. For RPM-based systems, including Fedora and SUSE, you should install gmp-devel, mpfr-devel and libmpc-devel (or mpc-devel on SUSE) packages. The packages will install the libraries and headers in standard system directories so they can be found automatically when building GCC.

      Configuration

      For example, configuring and building GCC 4.6.2 (with support for C, C++, Fortran and Go) should be as simple as:

      If your build fails and your configure command has lots of complicated options you should try removing options and keep it simple. Do not add lots of configure options you don’t understand, they might be the reason your build fails.

      None: InstallingGCC (последним исправлял пользователь JonathanWakely 2017-07-20 19:47:08)

      GCC Frequently Asked Questions

      This FAQ tries to answer specific questions concerning GCC. For general information regarding C, C++, and Fortran respectively, please check the comp.lang.c FAQ and the C++ FAQ.

      Other GCC-related FAQs: libstdc++-v3.

      Questions

      General information

      How do I get a bug fixed or a feature added?

      There are lots of ways to get something fixed. The list below may be incomplete, but it covers many of the common cases. These are listed roughly in order of decreasing difficulty for the average GCC user, meaning someone who is not skilled in the internals of GCC, and where difficulty is measured in terms of the time required to fix the bug. No alternative is better than any other; each has its benefits and disadvantages.

      Does GCC work on my platform?

      The host/target specific installation notes for GCC include information about known problems with installing or using GCC on particular platforms. These are included in the sources for a release in INSTALL/specific.html, and the latest version is always available at the GCC web site. Reports of successful builds for several versions of GCC are also available at the web site.

      Installation

      How to install multiple versions of GCC

      It may be desirable to install multiple versions of the compiler on the same system. This can be done by using different prefix paths at configure time and a few symlinks.

      Dynamic linker is unable to find GCC libraries

      This problem manifests itself by programs not finding shared libraries they depend on when the programs are started. (This often shows around libstdc++.)

      GCC does not specify a runpath so that the dynamic linker can find dynamic libraries at runtime.

      Another alternative is to install a wrapper script around gcc, g++ or ld that adds the appropriate directory to the environment variable LD_RUN_PATH or equivalent (again, it’s platform-dependent).

      GCC can not find GNU as/GNU ld

      GCC searches the PATH for an assembler and a linker, but it only does so after searching a directory list hard-coded in the GCC executables. Since, on most platforms, the hard-coded list includes directories in which the system assembler and linker can be found, you may have to take one of the following actions to arrange that GCC uses the GNU versions of those programs.

      cpp: Usage. Error

      If you get an error like this when building GCC (particularly when building __mulsi3), then you likely have a problem with your environment variables.

      First look for an explicit ‘.’ in either LIBRARY_PATH or GCC_EXEC_PREFIX from your environment. If you do not find an explicit ‘.’, look for an empty pathname in those variables. Note that ‘:’ at either the start or end of these variables is an implicit ‘.’ and will cause problems.

      Also note ‘::’ in these paths will also cause similar problems.

      Testsuite problems

      How can I run the testsuite with multiple options?

      This technique is particularly useful on multilibbed targets.

      Miscellaneous

      Friend Templates

      In order to make a specialization of a template function a friend of a (possibly template) class, you must explicitly state that the friend function is a template, by appending angle brackets to its name, and this template function must have been declared already. Here’s an example:

      If you meant bar to be a template function, you should have forward-declared it as follows. Note that, since the template function declaration refers to the template class, the template class must be forward-declared too:

      In this case, the template argument list could be left empty, because it can be implicitly deduced from the function arguments, but the angle brackets must be present, otherwise the declaration will be taken as a non-template function. Furthermore, in some cases, you may have to explicitly specify the template arguments, to remove ambiguity.

      An error in the last public comment draft of the ANSI/ISO C++ Standard and the fact that previous releases of GCC would accept such friend declarations as template declarations has led people to believe that the forward declaration was not necessary, but, according to the final version of the Standard, it is.

      The new C++ ABI in the GCC 3.0 series uses address comparisons, rather than string compares, to determine type equality. This leads to better performance. Like other objects that have to be present in the final executable, these std::type_info objects have what is called vague linkage because they are not tightly bound to any one particular translation unit (object file). The compiler has to emit them in any translation unit that requires their presence, and then rely on the linking and loading process to make sure that only one of them is active in the final executable. With static linking all of these symbols are resolved at link time, but with dynamic linking, further resolution occurs at load time. You have to ensure that objects within a shared library are resolved against objects in the executable and other shared libraries.

      Template instantiations are another, user visible, case of objects with vague linkage, which needs similar resolution. If you do not take the above precautions, you may discover that a template instantiation with the same argument list, but instantiated in multiple translation units, has several addresses, depending in which translation unit the address is taken. (This is not an exhaustive list of the kind of objects which have vague linkage and are expected to be resolved during linking & loading.)

      If you are worried about different objects with the same name colliding during the linking or loading process, then you should use namespaces to disambiguate them. Giving distinct objects with global linkage the same name is a violation of the One Definition Rule (ODR) [basic.def.odr].

      Why do I need autoconf, bison, xgettext, automake, etc?

      If you’re using diffs up dated from one snapshot to the next, or if you’re using the SVN repository, you may need several additional programs to build GCC.

      These include, but are not necessarily limited to autoconf, automake, bison, and xgettext.

      This is necessary because neither diff nor cvs keep timestamps correct. This causes problems for generated files as «make» may think those generated files are out of date and try to regenerate them.

      An easy way to work around this problem is to use the gcc_update script in the contrib subdirectory of GCC, which handles this transparently without requiring installation of any additional tools.

      If you modified some sources or when building from SVN you may also need some additional tools.

      Why can’t I build a shared library?

      When building a shared library you may get an error message from the linker like `assert pure-text failed:’ or `DP relative code in file’.

      This kind of error occurs when you’ve failed to provide proper flags to gcc when linking the shared library.

      When building C++, the linker says my constructors, destructors or virtual tables are undefined, but I defined them

      The ISO C++ Standard specifies that all virtual methods of a class that are not pure-virtual must be defined, but does not require any diagnostic for violations of this rule [class.virtual]/8. Based on this assumption, GCC will only emit the implicitly defined constructors, the assignment operator, the destructor and the virtual table of a class in the translation unit that defines its first such non-inline method.

      Therefore, if you fail to define this particular method, the linker may complain about the lack of definitions for apparently unrelated symbols. Unfortunately, in order to improve this error message, it might be necessary to change the linker, and this can’t always be done.

      The solution is to ensure that all virtual methods that are not pure are defined. Note that a destructor must be defined even if it is declared pure-virtual [class.dtor]/7.

      Copyright (C) Free Software Foundation, Inc. Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.

      How to reinstall gcc. Смотреть фото How to reinstall gcc. Смотреть картинку How to reinstall gcc. Картинка про How to reinstall gcc. Фото How to reinstall gccPreshing on Programming

      Several modern C++ features are currently missing from Visual Studio Express, and from the system GCC compiler provided with many of today’s Linux distributions. Generic lambdas – also known as polymorphic lambdas – are one such feature. This feature is, however, available in the latest versions of GCC and Clang.

      The following guide will help you install the latest GCC on Windows, so you can experiment with generic lambdas and other cutting-edge C++ features. You’ll need to compile GCC from sources, but that’s not a problem. Depending on the speed of your machine, you can have the latest GCC up and running in as little as 15 minutes.

      [Update: As a commenter points out, you can also install native GCC compilers from the MinGW-w64 project without needing Cygwin.]

      1. Install Cygwin

      First, download and run either the 32- or 64-bit version of the Cygwin installer, depending on your version of Windows. Cygwin’s setup wizard will walk you through a series of steps. If your machine is located behind a proxy server, make sure to check “Use Internet Explorer Proxy Settings” when you get to the “Select Your Internet Connection” step.

      When you reach the “Select Packages” step (shown below), don’t bother selecting any packages yet. Just go ahead and click Next. We’ll add additional packages from the command line later.

      How to reinstall gcc. Смотреть фото How to reinstall gcc. Смотреть картинку How to reinstall gcc. Картинка про How to reinstall gcc. Фото How to reinstall gcc

      How to reinstall gcc. Смотреть фото How to reinstall gcc. Смотреть картинку How to reinstall gcc. Картинка про How to reinstall gcc. Фото How to reinstall gcc

      If you already have Cygwin installed, it’s a good idea to re-run the installer to make sure it has the latest available packages. Alternatively, you can install a new instance of Cygwin in a different folder.

      2. Install Required Cygwin Packages

      Next, you’ll need to add several packages to Cygwin. You can add them all in one fell swoop. Just open a Command Prompt (in Windows), navigate to the folder where the Cygwin installer is located, and run the following command:

      How to reinstall gcc. Смотреть фото How to reinstall gcc. Смотреть картинку How to reinstall gcc. Картинка про How to reinstall gcc. Фото How to reinstall gcc

      A window will pop up and download all the required packages along with their dependencies.

      At this point, you now have a working GCC compiler on your system. It’s not the latest version of GCC; it’s whatever version the Cygwin maintainers chose as their system compiler. At the time of writing, that’s GCC 4.8.3. To get a more recent version of GCC, you’ll have to compile it yourself, using the GCC compiler you already have.

      3. Download, Build and Install the Latest GCC

      Open a Cygwin terminal, either from the Start menu or by running Cygwin.bat from the Cygwin installation folder.

      How to reinstall gcc. Смотреть фото How to reinstall gcc. Смотреть картинку How to reinstall gcc. Картинка про How to reinstall gcc. Фото How to reinstall gcc

      If your machine is located behind a proxy server, you must run the following command from the Cygwin terminal before proceeding – otherwise, wget won’t work. This step is not needed if your machine is directly connected to the Internet.

      To download and extract the latest GCC source code, enter the following commands in the Cygwin terminal. If you’re following this guide at a later date, there will surely be a more recent version of GCC available. I used 4.9.2, but you can use any version you like. Keep in mind, though, that it’s always best to have the latest Cygwin packages installed when building the latest GCC. Be patient with the tar command; it takes several minutes.

      Here’s a description of the command-line options passed to configure :

      We’re not going to build a new Binutils, which GCC relies on, because the existing Binutils provided by Cygwin is already quite recent. We’re also skipping a couple of packages, namely ISL and CLooG, which means that the new compiler won’t be able to use any of the Graphite loop optimizations.

      Next, we’ll actually build the new GCC compiler suite, including C, C++ and the standard C++ library. This is the longest step.

      How to reinstall gcc. Смотреть фото How to reinstall gcc. Смотреть картинку How to reinstall gcc. Картинка про How to reinstall gcc. Фото How to reinstall gcc

      Once that’s finished, install the new compiler:

      If, later, you decide to uninstall the new GCC compiler, you have several options:

      4. Test the New Compiler

      All right, let’s compile some code that uses generic lambdas! Generic lambdas are part of the C++14 standard. They let you pass arguments to lambda functions as auto (or any templated type), like the one highlighted below. Create a file named test.cpp with the following contents:

      You can add files to your home directory in Cygwin using any Windows-based text editor; just save them to the folder C:\cygwin64\home\Jeff (or similar) in Windows.

      First, let’s see what happens when we try to compile it using the system GCC compiler provided by Cygwin:

      If the system compiler version is less than 4.9, compilation will fail:

      How to reinstall gcc. Смотреть фото How to reinstall gcc. Смотреть картинку How to reinstall gcc. Картинка про How to reinstall gcc. Фото How to reinstall gcc

      How to reinstall gcc. Смотреть фото How to reinstall gcc. Смотреть картинку How to reinstall gcc. Картинка про How to reinstall gcc. Фото How to reinstall gcc

      Check out Plywood, a cross-platform, open source C++ framework:

      Recent Posts

      Installing GCC: Final installation

      Now that GCC has been built (and optionally tested), you can install it with

      We strongly recommend to install into a target directory where there is no previous version of GCC present. Also, the GNAT runtime should not be stripped, as this would break certain features of the debugger that depend on this debugging information (catching Ada exceptions for instance).

      Installation into a temporary staging area or into a chroot jail can be achieved with the command

      where path-to-rootdir is the absolute path of a directory relative to which all installation paths will be interpreted. Note that the directory specified by DESTDIR need not exist yet; it will be created if necessary.

      There is a subtle point with tooldirs and DESTDIR : If you relocate a cross-compiler installation with e.g. ‘ DESTDIR= rootdir ’, then the directory rootdir / exec-prefix / target-alias /bin will be filled with duplicated GCC executables only if it already exists, it will not be created otherwise. This is regarded as a feature, not as a bug, because it gives slightly more control to the packagers using the DESTDIR feature.

      You can install stripped programs and libraries with

      If you are bootstrapping a released version of GCC then please quickly review the build status page for your release, available from https://gcc.gnu.org/buildstat.html. If your system is not listed for the version of GCC that you built, send a note to gcc@gcc.gnu.org indicating that you successfully built and installed GCC. Include the following information:

      For other systems, you can include similar information if you think it is relevant.

      We’d also like to know if the host/target specific installation notes didn’t include your host/target information or if that information is incomplete or out of date. Send a note to gcc@gcc.gnu.org detailing how the information should be changed.

      If you find a bug, please report it following the bug reporting guidelines.

      Copyright (C) Free Software Foundation, Inc. Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.

      How can I install a specific version of gcc on ubuntu 18.04

      I’m trying to install gcc 7.3.0 on ubuntu 18.04. Ubuntu got updated and now my gcc is 7.5.0. I have seen other questions on stack overflow, but they are either for older versions which their solution doesn’t apply to me, or some newer solutions such as the one that suggests running :

      doesn’t work as they report I have a newer version installed :

      What should I do to install gcc7.3.0 next to the current 7.5.0?

      What I have done so far:

      I found a package here downloaded it and tried to install it like this:

      but it fails with this error :

      How to reinstall gcc. Смотреть фото How to reinstall gcc. Смотреть картинку How to reinstall gcc. Картинка про How to reinstall gcc. Фото How to reinstall gcc

      1 Answer 1

      Tested and confirmed using 18.04 on a box using an Intel core i5.

      [As a guest, I don’t have points enough to make active the 15 links that may be helpful. The first several of them are, therefore, «broken» by design.]

      This tells the tale. To jump to the «bottom line,» look for «Here’s the Script.»

      The history of the venture

      You’ve likely seen these,

      Since you want to keep both versions, those approaches don’t really apply. There are additional questions / answers that address forced installation of dependencies, but, again, that’ll leave you with «one version» instead of more than one.

      It’s likely that the dependency issue you have experienced follows from the installation presumption of upgrade («replacement») rather than parallel or independence («supplementation»).

      Installing multiple versions techniques exist, but there may be an issue distinguishing 7.3 from 7.5

      If it were possible to «comment,» one question would be this:

      However, one would need to distinguish between 7.3 and 7.5, which is different from distinguishing 7 from 8 from 9, as used on that example.

      To try that technique, one would likely need to remove 7.5 so as then to install it in an «alternative» context.

      Removal takes us down at least one of the following two paths. (Hint: this led to a brick wall, and maybe that’s Ok.)

      First, there’s just basic, wholesale removal.

      Since there’s no use of, thus no «invested» set up for, 7.5, here, i.e., no love loss, it became a topic of experimentation and testing.

      determined that likely packages to remove were/are these:

      sudo apt search gcc-7 | more

      sudo apt-get remove «gcc-7»

      Thus, secondly, that brings up the question of whether there is such thing as a partial removal. (Hint: there is, but it’s probably not a good idea.)

      (after sudo apt-get install aptitude ) (it’s Ok and even a good idea to get this functionality, but keep reading; this path led to a brick wall)

      sudo aptitude unmarkauto build-essential gcc g++ [which didn’t really change anything]

      sudo aptitude purge gcc-7

      This gets us to the «options» list, and there were 6 options for this system.

      And, the system’s follow-up was to this effect: «The system is now going to remove them all, anyway, no matter what,» which is likely how the system protects the user from «rpm hell,» i.e., goes to a long extent to prevent just this very sort of thing, namely partial removal.

      Since the option there was to remove everything, I stopped. Just got finished, after about 5-6 hours, installing the prior version that I needed and don’t want to go through that, again. (That’s a foreshadowing of how that prior version now exists and is installed so as even to be subject to this dilemma.)

      That’s just to say that if there’s nothing else there in the way of dependencies that you want to keep, then this is an alternative to the out-and-out «remove» process, either of which of these puts us right back into the same position of removing everything.

      That’s also to say that I haven’t gone back to revisit this to include running sudo ldconfig after adjusting those packages via unmarkauto and trying that partial removal mechanism. It’s sufficient to be aware of «rpm hell» and not rush into it.

      That wholesale removal would be followed, then, by a dual or multiple version install technique, for which there are at least the discussions already mentioned, as just examples of the existence of such option. Again, since gcc-7 presently now refers to 7.5, it may be possible, with enough specificity in package identification, to accomplish a dual install of 7.3 and 7.5. Haven’t tried anything like that, yet. Someone who has will be in a position to make comment on that whole angle of things. Maybe there truly is a simpler process.

      Intro to the shell script

      This time around, the installation location was

      In this context, then, one possible way to «read the silence» in the early stages after your posting of your question is that the answer you need isn’t something as simple as what may already exist. If that’s a valid «read» of the timing, here, and I’m new enough to the site not to know, yet, either way, then there’s that subtle confirmation that the solution you’re looking at is basically compiling from scratch, i.e., «the hard way.»

      Here’s the Script

      [As for addressing the concept of potentially stale/dead links in the future, if you want to include the edits you’ve made to the script, presuming it works for you as well as it did for me, I’ll let you post it. This contribution is already «long.»]

      Some thoughts going in.

      Another value in looking through the script is to see that there are five pieces involved:

      Each has a download step, and each has (at least) one source.

      Config matters (yes, there are two intended meanings, here)

      For 7.3, did some checking and found helpful information on this page:

      In one of the answers down the page, there’s a compiler output line with versions of each of these that are working in conjunction with 7.3.

      GNU C11 (Ubuntu 7.3.0-27ubuntu1

      18.04) version 7.3.0 (x86_64-linux-gnu)

      So, some «edits» to the script for 7.3 are these.

      line 14 gcc_version=7.3.0

      line 19 Uncomment this if you’d like.

      More about using multiple cores

      (Someone may want/need this.)

      Run this command: lscpu

      That command provides, among other items of information, these items in particular:

      At the identified site, CPU(s) = 32 = * *

      line 25
      Long story short about «unknown», it’s Ok to leave that as is.

      line 34 build_dir
      This is set to build in the tmp directory in «system file» area. That worked just fine.

      line 35 source_dir
      Left this one as is.

      line 36 tarfile_dir
      Left this one as is.

      line 40 packageversion
      Left this one as is.

      line 50 gmp_version
      Given the compiler info associated with 7.3 mentioned above, left this one as is.

      line 54 mpfr_version
      Given the compiler info above, changing this to 4.0.1 appears to be Ok.

      line 57 mpc_version
      Given the compiler info above, changing this to 1.1.0 appears to be Ok.

      line 60 isl_version
      Given the compiler info above, changing this to 0.19 appears to be Ok.

      line 170 gmp source page
      fine as is

      line 171 mpfr source page
      The page used by the script also has the 4.0.1 version, so it’s fine as is.

      line 173 isl source page
      The given infrastructure page has 0.18, but not 0.19. I changed this one to this site: http://isl.gforge.inria.fr/ (there was a momentary, flash-length only, pause while the connection was made to this overseas site; connection was just fine)

      line 174 gcc source page
      Change this to this site: https://ftp.gnu.org/gnu/gcc/gcc-7.3.0/

      lines 224, 225
      left as is

      line 291
      There’s enough going on that it made sense to uncomment this line to get these checks along the way.

      autogen kicks in here «at the end» to produce the documentation.

      Confirmation of installation

      I set up 7.4, and it’s now in the

      /opt directory. Reinstalling it to /opt (root/opt) may happen once confidence is higher that this is what I need.

      That said, this is a «how to» to get 7.3 installed along with the system’s «encouragement» to use 7.5.

      The shell script works to install a parallel version of the toolchain. Just be sure to have the info it needs put into the right places and to have already installed the utilities (functions, command line commands) used by it. «As is,» it’ll install into

      /opt. This can take «a while.» Here, it was a couple of hours.

      Источники информации:

      Добавить комментарий

      Ваш адрес email не будет опубликован. Обязательные поля помечены *