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 */


    return 0;
  • 1
    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

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

  • 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
  • 1
    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++.
    – goldilocks
    Apr 29 '13 at 15:57
  • It is C code, but cc1plus belongs to g++ afaik.
    – schaiba
    Apr 29 '13 at 15:59

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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