Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to learn system calls for open,write and close a file. I use this sample and the result is:

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

Here's my program:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>

int main (int argc, char *argv[])
{
    int fd1;
    char buf[128];
    fd1 = open("Desktop/this.txt", O_WRONLY);
    if (fd1 == -1) {
        perror("File cannot be opened");
        return EXIT_FAILURE;
    }

    /* Enter the data to be written into the file */
    scanf("%127s", buf);

    write(fd1, buf, strlen(buf)); /* fd1 is the file descriptor, buf is the character array used to
 hold the data, strlen(buf) informs the function that the number of bytes equal to the length of the
 string in the buffer need to be copied */

    close(fdl);

    return 0;
}
share|improve this question
    
Have you tried locate cc1plus? The issue is with installation of the compiler. –  Karlson Apr 29 '13 at 15:45
    
How does it work? –  Hanna Apr 29 '13 at 15:54
1  
You will need to be a little more specific on this question. –  Karlson Apr 29 '13 at 16:01
    
What do you mean?" more specific "? –  Hanna Apr 29 '13 at 16:42
    
How does it work? - How does what work? Be more specific. –  Karlson Apr 29 '13 at 16:54
show 1 more comment

2 Answers

up vote 1 down vote accepted

I presume you're using Ubuntu, Debian or some derivatives. Make sure your system is up to date and then install g++.

share|improve this answer
    
I'm using Ubuntu. how? –  Hanna Apr 29 '13 at 15:56
    
Open a terminal and type 'sudo apt-get install g++'. Without the quotes. –  schaiba Apr 29 '13 at 15:57
    
That's not C++ code, it's C and should be compiled as such. You need to make sure gcc is properly installed, and use that, not g++. –  TAFKA 'goldilocks' Apr 29 '13 at 15:57
    
It is C code, but cc1plus belongs to g++ afaik. –  schaiba Apr 29 '13 at 15:59
    
Updating works!!!thanks –  Hanna Apr 29 '13 at 16:12
add comment

cc1plus is a component of a C++ compiler. You're trying to compile a C program. The gcc command determines which compiler to invoke based on the name of the source file: a C compiler for .c, a C++ compiler for .cc or .C, a Pascal compiler for .p, an assembler for .s, etc.

It seems that you gave your program a name that indicates a C++ program. Do note that Linux file names are case sensitive. C source files must have the extension .c (lowercase c), not .C. Unix users tend to use mostly lowercase letters in file names, and in particular almost all conventional file extensions are in lowercase. So make sure to use lowercase file names.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.