-7

I tried to run a basic C++ file in the terminal:

#include <iostream>

using namespace std;

int main() {
    cont << "This is my first C++ program!";
    return 0
}

And then tried to run it in the terminal:

make learningCPP.cpp

    make: *** No rule to make target `learningCPP.cpp'.  Stop.

And tried:

make learningCPP

    make: *** No rule to make target `learningCPP'.  Stop.

And tried:

gcc learningCPP.cpp -o learningCPP.out

    clang: error: no such file or directory: 'learningCPP.cpp'
    clang: error: no input files

Here is the entire Bash/Clang file:

Last login: Mon May 25 07:49:21 on console

make learningCPP.cpp

    make: *** No rule to make target `learningCPP.cpp'.  Stop.

make learningCPP

    make: *** No rule to make target `learningCPP'.  Stop.

gcc learningCPP.cpp -o learningCPP.out

    clang: error: no such file or directory: 'learningCPP.cpp'
    clang: error: no input files

$ g++ -o lab21 learningCPP.cpp

    -bash: $: command not found

$ ./lab21

    -bash: $: command not found

./learningCPP.cpp

    -bash: ./learningCPP.cpp: No such file or directory

./main

    -bash: ./main: No such file or directory

$ g++ -o main learningCPP.cpp

    -bash: $: command not found

cpp

make learningCPP.cpp

run

How can I fix it?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 6
    `clang: error: no such file or directory: 'learningCPP.cpp'` -- Was your file called `learningCPP.cpp`? And was it in the current directory? It sounds like `g++` isn't installed on this machine. What does `g++ -v` output? – David Schwartz May 25 '15 at 23:08
  • 1
    Type in `ls` and press Enter. Is `learningCpp.cpp` one of the files listed? – Sumner Evans May 25 '15 at 23:09
  • 2
    The input shows no attempts to execute g++. There's always a bogus `$` before it. – aschepler May 25 '15 at 23:10
  • You don't "run" cpp files, you compile them. It appears you weren't paying attention during a really important part of your class. – kfsone May 25 '15 at 23:12
  • _`cont << ... `_ You're sure about this line of code? – πάντα ῥεῖ May 25 '15 at 23:35
  • Yes I'm sure about the code. And I'm teaching myself. I'm not out of middle school yet. The output of g++ -v was: Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/4.2.1 Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn) Target: x86_64-apple-darwin14.3.0 Thread model: posix. The program was put in a folder called C++ in a folder called Coding. ls returned the Coding folder and I couldn't get further. That was amouthful – Kawika Dembroski May 29 '15 at 00:41
  • I am voting to ***delete this question*** because it has very little value without more information from the OP about the current directory and its contents. And the OP is probably never coming back - *"Last seen more than 5 years ago"*. – Peter Mortensen Apr 24 '22 at 18:39

1 Answers1

2

Judging by the errors, your file either isn't called learningCPP.cpp, or isn't in the directory you're trying to compile it from.

Rename it so it has that name, or change directory to its location, then the build command is

g++ learningCPP.cpp -o learningCPP

not gcc, and with no spurious $ before it. Alternatively, as long as the source file is present in the working directory, you could use make learningCPP.

Once that succeeds, run the program with

./learningCPP

although you'll have to read the new error messages, and use that to figure out how to fix the syntax errors, before it will compile.

Mike Seymour
  • 249,747
  • 28
  • 448
  • 644