Compile c program with php meet the "gcc: error trying to exec 'cc1': execvp: No such file or directory" problem

Issues related to applications and software problems
Post Reply
starlitsky
Posts: 2
Joined: 2019/06/07 14:38:07

Compile c program with php meet the "gcc: error trying to exec 'cc1': execvp: No such file or directory" problem

Post by starlitsky » 2019/06/07 15:45:47

I want to build an online compiler with php, but when I want to compile the C file, I will get some wrong, but I can't figure out that reason.
When I use the terminal to compile the c file it was normal but through the php to do that will get the error message:

Code: Select all

"gcc: error trying to exec 'cc1': execvp: No such file or directory"

Code: Select all

My OS: CentOS Linux release 7.6.1810 (Core)

Code: Select all

gcc --version:
        gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)
        Copyright (C) 2015 Free Software Foundation, Inc.
        This is free software; see the source for copying conditions.  There is NO
        warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Code: Select all

which gcc :
        /usr/bin/gcc
And I also set the PATH to ensure that /usr/bin was at the most begin, by

Code: Select all

PATH=/usr/bin:$PATH
.

I simply take a code that someone says they can work, but that still failed for me. Below is the code I found.

Code: Select all

<?php
$data = '#include<stdio.h> 
 
int main(){
printf("Hello World");
return 0;
}
 
';
 
$my_file = 'code.c';
file_put_contents($my_file, $data);
 
system("gcc {$my_file} &> error.txt");
 
$error = file_get_contents("error.txt");
 
if($error=='')
    system("./a.out");
else
    echo $error;
?>
I have searched for this problem for a long time, but I still can't get a proper answer.
And I try to reinstall the gcc and g++ for many times, but the error remains...
Hope somebody can know why to have this problem. :)

User avatar
TrevorH
Forum Moderator
Posts: 26500
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Compile c program with php meet the "gcc: error trying to exec 'cc1': execvp: No such file or directory" problem

Post by TrevorH » 2019/06/07 15:57:23

It's trying to run a program called 'cc1' and you do not have it installed. Run yum provides '*/cc1' and yum will list the packages that provide that file. Now you can install the package. Hint: you probably want cpp-4.8.5-36.el7_6.2.x86_64 installed.
CentOS 5 died in March 2017 - migrate NOW!
CentOS 6 goes EOL sooner rather than later, get upgrading!
Full time Geek, part time moderator. Use the FAQ Luke

starlitsky
Posts: 2
Joined: 2019/06/07 14:38:07

Re: Compile c program with php meet the "gcc: error trying to exec 'cc1': execvp: No such file or directory" problem

Post by starlitsky » 2019/06/07 16:33:23

Actually, I can found the 'cc1' file under the 4.8.5 directory, but it seems not to be found.

I tried the command below:

Code: Select all

sudo yum  install cpp-4.8.5-36.el7_6.2.x86_64
And I get the message that I have been installed:

Code: Select all

Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                                             | 7.7 kB  00:00:00
 * base: mirror01.idc.hinet.net
 * epel: mirror01.idc.hinet.net
 * extras: mirror01.idc.hinet.net
 * remi-php73: mirror.innosol.asia
 * remi-safe: ap.stykers.moe
 * updates: mirror01.idc.hinet.net
extras                                                                           | 3.4 kB  00:00:00
mariadb                                                                          | 2.9 kB  00:00:00
remi-php73                                                                       | 3.0 kB  00:00:00
remi-safe                                                                        | 3.0 kB  00:00:00
updates                                                                          | 3.4 kB  00:00:00
(1/2): remi-php73/primary_db                                                     | 198 kB  00:00:16
(2/2): remi-safe/primary_db                                                      | 1.6 MB  00:00:17
Package cpp-4.8.5-36.el7_6.2.x86_64 already installed and latest version
Nothing to do

Post Reply

Return to “CentOS 7 - Software Support”