Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: gcc: error trying to exec "cc1": execvp: no such file or directory

  1. #1
    Join Date
    Dec 2010
    Beans
    15
    Distro
    Ubuntu 10.10 Maverick Meerkat

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

    I've been working on a shell for my Operating Systems course. My shell can't compile or run any programs using the gcc command. I get the following error when I try:

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

    It was never stated that I need to be able to compile or run programs, but I'd like to implement it anyway. I appreciate any help or suggestions.

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<unistd.h>
    #include<string.h>
    #include<fcntl.h>
    #include<errno.h>
    
     /****************************************************************************
    ** Shawn Taylor
    ** CSC425 Project 1
    ** Felt Grace Shell version 1.0
    ** 11/4/2011
    ******************************************************************************/
    extern int errno;
    
    void parse(char *string, char **args, int signal)
    {
    	int code = signal;
    	char delimiter;
    
    	if(code == 0)
    		delimiter = ' ';
    	else
    		delimiter = ':';
    
    	char *tok = strtok(string, &delimiter);
    
    	int i = 0;
    	while(tok != NULL)
    	{
    		args[i] = malloc(sizeof(char) * strlen(tok));
    		strcpy(args[i], tok);
    
    		if(code == 1)
    			strncat(args[i], "/", 1);
    
    		tok = strtok(NULL, &delimiter);
    		i++;
    	}
     	//terminate my_argv and my_envp
    	args[i] = (char *)0;	
    }
    
    int attach_path(char *cmd, char **args)
    {
    	char tempPath[128];
    	int file;
    
    	int i;
    	for(i = 0; args[i] != NULL; i++) //search path for args
    	{	
    		strcpy(tempPath, args[i]);
    		strcat(tempPath, cmd);
    		
    		if((file = open(tempPath, O_RDONLY)) > 0)
    		{
    			if(faccessat(0, tempPath, F_OK, 0) == 0)
    			{
    				strcpy(cmd, tempPath);
    				close(file);
    				break;
    			}
    			else
    			{
    				close(file);
    				printf("Access Denied\n");
    			}
    		}
    	}
    
    	return 0;
    }
    
    void execute_command(char *path_arg, char **opts_args, char**env_args)
    {
    	int i;
    	int pId = fork();
    	
    	if(pId == 0)
    	{	
    		i = execve(path_arg, opts_args,env_args);
    		if(i != 0)
    		{				
    			printf("error: %s\n", strerror(errno));
    			printf("%s: %s\n", path_arg,"Command Not Found");
    			exit(1);
    		}
    	}
    	else
    	{
    		wait(NULL);
    	}
    }
    
    int main(int argc, char **argv, char **envp)
    {
    	char dir[50];
    	char command[128];
    	char *my_argv[100];
    	char *my_envp[100];
    
    	//Get environment and parse it
    	char *environment = getenv("PATH");
    	parse(environment, my_envp, 1);
    
    	//Get user environment
    	char* userEnvironment = getenv("USER");
    	strncat(userEnvironment,"@~",2);
    	
    	//Clear screen and start shell
    	int index;
    	for(index = 0; index < 100; index++)
    	{
    		putchar('\n');
    	}
    
    	printf("***************************\n");
    	printf("%s\n","***** Felt Grace v1.0 *****");
    	printf("***************************\n");
    
    	while(1)
    	{	
    		//show the prompt with current directory
    		printf("%s%s$ ", userEnvironment, getcwd(NULL, 0));
    		
    		//Get command input and create termporary copy
    		fgets(command,127,stdin);
    		char* commandCopy = command;
    		
    		if(strncmp(command, "exit", 4) == 0)
    		{	
    			printf("***************************\n");
    			return 0;
    		}
    
    		//Parse command
    		parse(commandCopy, my_argv, 0);
    
    		//attach path to command
    		attach_path(command, my_envp);
    			
    		if(strncmp(my_argv[0], "cd", 2) == 0)
    		{
    			int dirChange;
    			dirChange = chdir(my_argv[1]);
    				
    			if(dirChange != 0)
    				printf("%s\n", "Error Changing Directory");
    		}
    		else
    		if(strncmp(my_argv[0], "execute", 7) == 0)
    		{
    			FILE* file;
    			file = fopen(my_argv[1], "r");
    			char batch_command[128];
    			char batchCommandCopy[128];
    				
    			//Loop through file and get commands
    			while(fgets(batch_command, 128, file) != NULL)
    			{	
    				int i;
    				char c;
    				for(i = 0; i < strlen(batch_command); i++)
    				{
    					c = batch_command[i];
    					if(c != '\n')
    						batchCommandCopy[i] = batch_command[i];
    					else
    						batchCommandCopy[i] = (char)0;
    				}
    					
    				//Attach Path to batch command			
    				attach_path(batchCommandCopy, my_envp);
    				
    				printf("\n");
    
    				//Execute batch command
    				execute_command(batchCommandCopy, argv, my_envp);	
    
    				printf("\n");
    			}
    			
    				fclose(file);
    		}
    		else
    		{
    			//Execute single command
    			execute_command(command, my_argv, my_envp);
    		}		
    		
    		int i; 	
    		for(i = 0; my_argv[i] != NULL; i++)
    		{
    			free(my_argv[i]);
    		}
    	}
    
    	int i;
    	for(i = 0; my_envp[i] != NULL; i++)
    	{
    		free(my_envp[i]);
    	}
    	
    	return 0;
    }

  2. #2
    Join Date
    Jul 2010
    Beans
    85

    Re: gcc: error trying to exec "cc1": execvp: no such file or directory

    you need to install.i am assuming you are using fedora/rhel/centos

    Code:
    yum install gcc-c++

  3. #3
    Join Date
    Dec 2010
    Beans
    15
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: gcc: error trying to exec "cc1": execvp: no such file or directory

    This program is in C. gcc works works in bash, just not in my shell. I'm using ubuntu. Sorry for not mentioning that before.

  4. #4
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,294
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: gcc: error trying to exec "cc1": execvp: no such file or directory

    First: turn on all compiler warnings (-pedantic -Wall -Wextra) and run your program in valgrind. You have a lot of memory leaks, buffer overflows and other problems. And it segfaults when you just press Enter without typing anything.

    Quote Originally Posted by learnbash View Post
    you need to install.i am assuming you are using fedora/rhel/centos

    Code:
    yum install gcc-c++
    Awesome: someone posts on Ubuntu Forums, assume they're running Fedora.
    Last edited by Bachstelze; November 6th, 2011 at 05:06 PM.

  5. #5
    Join Date
    Jul 2010
    Beans
    85

    Re: gcc: error trying to exec "cc1": execvp: no such file or directory

    i am sorry sir that was just assumption.

  6. #6
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,294
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: gcc: error trying to exec "cc1": execvp: no such file or directory

    Also why do you clear the screen when your shell starts? It's annoying and no real shell does that.

    (Yes, yes, I am looking at the problem you described too, but it's more complicated. )

  7. #7
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,294
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: gcc: error trying to exec "cc1": execvp: no such file or directory

    Basically, cc1 is not in your PATH. But it's not in your PATH when you run gcc from a "normal" shell either, so I'm not sure what it is that you do differently and prevents gcc from finding cc1 when it tries to run it...

  8. #8
    Join Date
    Dec 2010
    Beans
    15
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: gcc: error trying to exec "cc1": execvp: no such file or directory

    I'm trying your suggestions now. Just finished installing Valgrind. Segmentation fault after hitting enter with nothing entered...ugh. I'll correct that.

    As for the clear screen thing, I just thought it would be nice to clear the screen and start fresh; though I would rather have the prompt appear on the top of the console. That's low priority right now though.

  9. #9
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,294
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: gcc: error trying to exec "cc1": execvp: no such file or directory

    See posts above that were moved~~

  10. #10
    Join Date
    Dec 2010
    Beans
    15
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: gcc: error trying to exec "cc1": execvp: no such file or directory

    I fixed the segmentation faults that I found. Still getting that 'cc1' error though. Not sure how to fix that yet. Valgrind says I have no leaks but 1 file open.

    Updated Code:
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<unistd.h>
    #include<string.h>
    #include<fcntl.h>
    #include<errno.h>
    #include<sys/wait.h>
     /****************************************************************************
    ** Shawn Taylor
    ** CSC425 Project 1
    ** Felt Grace Shell version 1.0
    ** 11/4/2011
    ******************************************************************************/
    extern int errno;
    
    void parse(char *string, char **args, int signal)
    {
    	int code = signal;
    	char delimiter;
    	char *tok;
    	int i;
    	
    	if(code == 0)
    		delimiter = ' ';
    	else
    		delimiter = ':';
    	
    	i = 0;
    	tok = strtok(string, &delimiter);
    
    	while(tok != NULL)
    	{
    		args[i] = malloc(sizeof(char) * strlen(tok));
    		strcpy(args[i], tok);
    
    		if(code == 1)
    			strncat(args[i], "/", 1);
    
    		tok = strtok(NULL, &delimiter);
    		i++;
    	}
    
     	/*terminate my_argv and my_envp*/
    	args[i] = (char *)0;	
    }
    
    int attach_path(char *cmd, char **args)
    {
    	char tempPath[128];
    	int file;
    	int i;
    
    	for(i = 0; args[i] != NULL; i++) /*search path for args*/
    	{	
    		strcpy(tempPath, args[i]);
    		strcat(tempPath, cmd);
    		
    		if((file = open(tempPath, O_RDONLY)) > 0)
    		{
    			if(faccessat(0, tempPath, F_OK, 0) == 0)
    			{
    				strcpy(cmd, tempPath);
    				close(file);
    				break;
    			}
    			else
    			{
    				close(file);
    				printf("Access Denied\n");
    			}
    		}
    	}
    
    	return 0;
    }
    
    void execute_command(char *path_arg, char **opts_args, char**env_args)
    {
    	int i;
    	int pId = fork();
    	
    	if(pId == 0)
    	{	
    		i = execve(path_arg, opts_args,env_args);
    		if(i != 0)
    		{				
    			printf("error: %s\n", strerror(errno));
    			printf("%s: %s\n", path_arg,"Command Not Found");
    			exit(1);
    		}
    	}
    	else
    	{
    		wait(NULL);
    	}
    }
    
    int main(int argc, char **argv, char **envp)
    {
    	char command[128];
    	char *my_argv[100];
    	char *my_envp[100];
    	char *environment;
    	char* userEnvironment;
    	int index;
    
    	/*Get environment and parse it*/
    	environment = getenv("PATH");
    	parse(environment, my_envp, 1);
    
    	/*Get user environment*/
    	userEnvironment = getenv("USER");
    	strncat(userEnvironment,"@~",2);
    	
    	/*Clear screen and start shell*/
    	for(index = 0; index < 100; index++)
    	{
    		putchar('\n');
    	}
    
    	printf("***************************\n");
    	printf("%s\n","***** Felt Grace v1.0 *****");
    	printf("***************************\n");
    	
    	start: 
    	while(1)
    	{	
    		char* commandCopy;
    		
    		do
    		{
    			/*show the prompt with current directory*/
    			printf("%s%s$ ", userEnvironment, getcwd(NULL, 0));
    
    			/*Get command input and create termporary copy*/	
    			fgets(command,127,stdin);
    			commandCopy = command;
    		}
    
    		/*Checks for empty string*/
    		while((strncmp(command, "\n", 1)) == 0);
    		
    		if((strncmp(command, "exit", 4)) == 0)
    		{	
    			printf("***************************\n");
    			return 0;
    		}
    
    		/*Parse command*/
    		parse(commandCopy, my_argv, 0);
    
    		/*attach path to command*/
    		attach_path(command, my_envp);
    			
    		if(strncmp(my_argv[0], "cd", 2) == 0)
    		{
    			int dirChange;
    			dirChange = chdir(my_argv[1]);
    				
    			if(dirChange != 0)
    				printf("%s\n", "Error Changing Directory");
    		}
    		else
    		if(strncmp(my_argv[0], "execute", 7) == 0)
    		{
    			char batch_command[128];
    			char batchCommandCopy[128];
    			FILE *file;
    			
    			/*Test for valid file input after typing "execute"*/
    			if(my_argv[1] == NULL)
    				goto start;
    			if(strstr(my_argv[1], ".bat") == NULL)
    				goto start;
    
    			file = fopen(my_argv[1], "r");
    				
    			/*Loop through file and get commands*/
    			while(fgets(batch_command, 128, file) != NULL)
    			{	
    				char c;
    				int commandLength;
    				int index;
    
    				commandLength = strlen(batch_command);
    
    				for(index = 0; index < commandLength; index++)
    				{
    					c = batch_command[index];
    
    					if(c != '\n')
    						batchCommandCopy[index] = batch_command[index];
    					else
    						batchCommandCopy[index] = (char)0;
    				}
    					
    				/*Attach Path to batch command*/		
    				attach_path(batchCommandCopy, my_envp);
    				
    				printf("\n");
    
    				/*Execute batch command*/
    				execute_command(batchCommandCopy, argv, my_envp);	
    
    				printf("\n");
    				
    				fclose(file);
    			}
    			
    		}
    		else
    		{
    			/*Execute single command*/
    			execute_command(command, my_argv, my_envp);
    		}	
    	
    		for(index = 0; my_argv[index] != NULL; index++)
    		{
    			free(my_argv[index]);
    		}
    	}
    
    	for(index = 0; my_envp[index] != NULL; index++)
    	{
    		free(my_envp[index]);
    	}
    	
    	return 0;
    }
    Valgrind Output:
    Code:
    ==31497== Memcheck, a memory error detector
    ==31497== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
    ==31497== Using Valgrind-3.6.1-Debian and LibVEX; rerun with -h for copyright info
    ==31497== Command: test
    ==31497== 
    --31497-- Valgrind options:
    --31497--    --suppressions=/usr/lib/valgrind/debian-libc6-dbg.supp
    --31497--    --tool=memcheck
    --31497--    --leak-check=yes
    --31497--    --show-reachable=yes
    --31497--    --num-callers=20
    --31497--    --track-fds=yes
    --31497--    -v
    --31497-- Contents of /proc/version:
    --31497--   Linux version 3.0.0-12-generic (buildd@vernadsky) (gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3) ) #20-Ubuntu SMP Fri Oct 7 14:50:42 UTC 2011
    --31497-- Arch and hwcaps: X86, x86-sse1-sse2
    --31497-- Page sizes: currently 4096, max supported 4096
    --31497-- Valgrind library directory: /usr/lib/valgrind
    --31497-- Reading syms from /lib/i386-linux-gnu/ld-2.13.so (0x4000000)
    --31497--   Considering /lib/i386-linux-gnu/ld-2.13.so ..
    --31497--   .. CRC mismatch (computed 1a2ed160 wanted fece6135)
    --31497--   Considering /usr/lib/debug/lib/i386-linux-gnu/ld-2.13.so ..
    --31497--   .. CRC is valid
    --31497-- Reading syms from /usr/bin/test (0x8048000)
    --31497--   Considering /usr/bin/test ..
    --31497--   .. CRC mismatch (computed ee5926fa wanted a3840d1e)
    --31497--    object doesn't have a symbol table
    --31497-- Reading syms from /usr/lib/valgrind/memcheck-x86-linux (0x38000000)
    --31497--    object doesn't have a dynamic symbol table
    --31497-- Reading suppressions file: /usr/lib/valgrind/debian-libc6-dbg.supp
    --31497-- Reading suppressions file: /usr/lib/valgrind/default.supp
    --31497-- REDIR: 0x4016b80 (index) redirected to 0x3803e847 (vgPlain_x86_linux_REDIR_FOR_index)
    --31497-- Reading syms from /usr/lib/valgrind/vgpreload_core-x86-linux.so (0x4022000)
    --31497-- Reading syms from /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so (0x4025000)
    ==31497== WARNING: new redirection conflicts with existing -- ignoring it
    --31497--     new: 0x04016b80 (index               ) R-> 0x04028c7e index
    --31497-- REDIR: 0x4016d40 (strlen) redirected to 0x4029045 (strlen)
    --31497-- Reading syms from /lib/i386-linux-gnu/libc-2.13.so (0x4040000)
    --31497--   Considering /lib/i386-linux-gnu/libc-2.13.so ..
    --31497--   .. CRC mismatch (computed 365f96ac wanted ff3422fe)
    --31497--   Considering /usr/lib/debug/lib/i386-linux-gnu/libc-2.13.so ..
    --31497--   .. CRC is valid
    --31497-- REDIR: 0x40b6630 (rindex) redirected to 0x4028adc (rindex)
    --31497-- REDIR: 0x40b5d00 (__GI_strcmp) redirected to 0x4029a0a (__GI_strcmp)
    --31497-- REDIR: 0x40b6310 (__GI_strlen) redirected to 0x402902a (__GI_strlen)
    --31497-- REDIR: 0x40b5b40 (index) redirected to 0x4028bc7 (index)
    --31497-- REDIR: 0x40bc8b0 (__GI_strncmp) redirected to 0x40294b2 (__GI_strncmp)
    --31497-- REDIR: 0x40b8ba0 (strchrnul) redirected to 0x402ab9f (strchrnul)
    --31497-- REDIR: 0x40b2430 (malloc) redirected to 0x40287f1 (malloc)
    --31497-- REDIR: 0x40b28e0 (free) redirected to 0x4027b7d (free)
    ==31497== 
    ==31497== FILE DESCRIPTORS: 1 open at exit.
    ==31497== Open file descriptor 0: /dev/pts/0
    ==31497==    <inherited from parent>
    ==31497== 
    ==31497== 
    ==31497== HEAP SUMMARY:
    ==31497==     in use at exit: 0 bytes in 0 blocks
    ==31497==   total heap usage: 32 allocs, 32 frees, 2,017 bytes allocated
    ==31497== 
    ==31497== All heap blocks were freed -- no leaks are possible
    ==31497== 
    ==31497== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 11 from 6)
    --31497-- 
    --31497-- used_suppression:     11 U1004-ARM-_dl_relocate_object
    ==31497== 
    ==31497== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 11 from 6)

Page 1 of 3 123 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •