Score:0

errors when compiling with gcc

cn flag

I'm using ubuntu18.04 on the server. I have already installed gcc-4.9 under the root, but now I want to install gcc-7.4 under my own directory, so I did the following things. First I downloaded gcc-7.4.0.tar.gz, and extracted it.Then cd gcc-7.4.0/ and then download prerequisites using command ./contrib/download_prerequisites, then I run

mkdir build

and

cd build

I want to install gcc-7.4 under my directory without root, so I assigned prefix=/home/myusername/bin/ to compile. The complete command is as follow.

../configure --prefix=/home/xxx/bin --enable-shared --enable-threads=posix --enable-languages=c,c++,fortran --disable-multilib

but then I got an error.So I looked into the config.log file ,which says:

Thread model: posix
gcc version 4.9.3 (Ubuntu 4.9.3-13ubuntu2) 
configure:4314: $? = 0
configure:4303: gcc -V >&5
gcc: error: unrecognized command line option '-V'
gcc: fatal error: no input files
compilation terminated.
configure:4314: $? = 4
configure:4303: gcc -qversion >&5
gcc: error: unrecognized command line option '-qversion'
gcc: fatal error: no input files
compilation terminated.
configure:4314: $? = 4
configure:4334: checking for C compiler default output file name
configure:4356: gcc    conftest.c  >&5
gcc: error trying to exec 'cc1': execvp: No such file or directory
configure:4360: $? = 1
configure:4397: result: 
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| /* end confdefs.h.  */
| 
| int
| main ()
| {
| 
|   ;
|   return 0;
| }
configure:4403: error: in `/home/zxw/gcc-7.4.0/build':
configure:4407: error: C compiler cannot create executables
See `config.log' for more details.

it says C compiler cannot create executables,and also trying to exec 'cc1': execvp: No such file or directory. I searched both issues and referred to this one,but it doesn't help.

I am new to this and don't know exactly what's going on. Can anyone helps me? If you need more information, please tell me, I don't know what can I do to check it further.

update:
1.I can't install both versions system-wide, because I am preparing an environment on my lab's server which I don't have the root access. So this is why I tried to install the particular gcc version I need under my directory.
2. The reason why I need gcc-7.4.0 is because I'm preparing an environment for the detectron2 project, which is a project provided by Facebook and is used to learn object detection. And from the installation requirements of detectron2, I need to prepare cuda and gcc first, I now have cuda-10.1,ubuntu-18.04 ,so I searched for which version of gcc do I need, and from the nvidia official website, it says the gcc version that matches cuda-10.1 and ubuntu-18.04 is and only is gcc-7.4, so I am installing this particular version of gcc.
3.I'm sorry I don't know how the gcc-4.9 installed, the reason is the same as point 1, I am just a user of my lab's server, it has already been here since I joined the lab.

second update. I followed this and tried again, the command I used are as below.

tar xzf gcc-7.4.0.tar.gz
cd gcc-7.4.0
./contrib/download_prerequisites
cd ..
mkdir objdir
cd objdir
/home/xxx/gcc-7.4.0/configure --prefix=/home/xxx/GCC-7.4.0

and then received the same error report.
I doubt there is something wrong with the existing gcc version, so I can't build a new version based on the previous gcc.

hr flag
The error suggests there's a problem with your current (gcc-4.9?) installation - does its `cc1` executable actually exist where `gcc` can find it? I have `gcc-4.8` on my 18.04 system and it's `/usr/lib/gcc/x86_64-linux-gnu/4.8/cc1` for example.
sancho.s ReinstateMonicaCellio avatar
As shown in one of the links posted in my answer, (see [this](https://askubuntu.com/a/647593/226614)), `gcc-4.9` might be missing some complements... (libc6, build-essentials, etc.)
hr flag
FWIW I followed your second method on my 18.04 box with gcc-4.8 (specifically 4.8.5-4ubuntu8 from the bionic/universe repo) and it configured fine and (eventually) built successfully. I don't think there's an issue with gcc-4.9 being "too old" to build it
Score:0

EDIT.

  1. You may try installing a precompiled gcc-7.4.0 only for your user, 1, 2, YMMV.

Recommendations and other notes:

  1. Install both versions system-wide. Then use update-alternatives to choose which is the default version to be used. Actually, that is often times done automatically during the installation process, and you can later on change your selection via update-alternatives, see this.
    And you can also choose which version to use for each user, like here. This is way simpler than what you are trying to do, and it will make both versions available for all users.

  2. If you have any reason for still preferring your method (it would be helpful if you stated your reason/s, others might also provide further insight), I suggest you follow this (with suitable version number). It appears you skipped/changed part of it. For instance, a typical location is --prefix=/home/xxx/gcc-<version>, not --prefix=/home/xxx/bin. Regardless whether that is the cause of problems, I suggest you start with the listed commands, and if it works then start adding configure flags as wanted.

  3. You might consider installing precompiled packages for the prerequisites, instead of ./contrib/download_prerequisites, as described here.

  4. Please post the exact command you used to "already installed gcc-4.9 under the root" (please take your 30 seconds for this). Installation "under the root" is not something you would typically want to do.

  5. I would go first with the suggestions, instead of trying to debug why you got the errors you got. Just to provide a few pointers to possible causes (will not delve further into this):

    5.1. For gcc: error: unrecognized command line option '-V': 1, 2.

    5.2. For gcc: error: unrecognized command line option '-qversion': see above.

    5.3. For gcc: error trying to exec 'cc1': execvp: No such file or directory: 1.

    5.4. For configure:4407: error: C compiler cannot create executables: 1 as an example. One of your configure options is likely the culprit. Start as indicated in item 2.

Kyrie Erving avatar
cn flag
Thanks a lot. I have updated some information you mentioned and I am trying to do those steps you've mentioned, I'll update again after I finish them.
hr flag
`5.1` and `5.2` look totally normal to me - the `./configure` script tries a bunch of options to determine what the build environment looks like
sancho.s ReinstateMonicaCellio avatar
@steeldriver - Agreed.
Score:0
ph flag

I immediately noticed this:

Thread model: posix
gcc version 4.9.3 (Ubuntu 4.9.3-13ubuntu2) 

It seems as though it's trying to use the old version of gcc you had installed, 4.9, to build 7.4. I looked around a little and didn't find an indication of which older versions of gcc are capable of building newer versions, but I wouldn't be surprised if 7.4 uses features that 4.9 doesn't support.

Is there a particular reason you need to use 4.9.3 to build 7.4.0? If not, I'd suggest installing Ubuntu's pre-built version of gcc (sudo apt install gcc-7), which looks like it will provide 7.5.0 on Ubuntu 18.04, and use that instead.

Kyrie Erving avatar
cn flag
Thanks a lot, the reason why I need to use `gcc-7.4` is that the nvidia website says the only version of gcc that matches `cuda-10.1` and `ubuntu 18.04` is `gcc-7.4`, so I just tried to install the particular version 7.4 instead of using pre built version of gcc which may provide me with verision 7.5.
Knud Larsen avatar
by flag
gcc-7.5 is a bug fix version of "7.4". .... Are you sure gcc-7.5 doesn't work with CUDA ? ..... Building gcc-7.4 : The system compiler g++-7.5 / gcc-7.5 is required.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.