I'm trying to make a simple script that will compile test.cpp but I cannot get it to work. I'm running the script like this:
> bash make.sh
And getting the following error:
: No such file or directory
g++: no input files
make.sh: line 3: ./test.out: No such file or directory
Here is make.sh:
#!/bin/sh
g++ -o ./test.out ./test.cpp
./test.out
I've tried it without the " ./ " and it still doesn't work. I am running Cygwin on Windows 7 with all the proper packages installed (I can compile and run from the shell itself, just not from script).
-
Replace ./ with absolute path! For Example: /home/MyName/test.cppSepahrad Salour– Sepahrad Salour2013年05月31日 17:02:26 +00:00Commented May 31, 2013 at 17:02
-
You need to run this in the same directory.Daniel Beck– Daniel Beck ♦2013年05月31日 17:03:28 +00:00Commented May 31, 2013 at 17:03
-
what are the permissions on the script file? is the execute bit turned on?Frank Thomas– Frank Thomas2013年05月31日 18:21:34 +00:00Commented May 31, 2013 at 18:21
1 Answer 1
Did you create make.sh with Notepad? If so, every line ends with a CR (carriage return) and a LF (line feed). Cygwin and its Unix-like programs cannot handle that; Unix expects lines in text files to end with just a LF (which Unix calls a "new line" character). Edit your file with a Cygwin editor (e.g., vi or vim) and fix it. If you cannot do that, try adding "; #" to the end of each line; that should cause bash to treat the offending CRs as comments.
To expand on the above: if my theory is correct, the second line of make.sh looks like:
g++ -o ./test.out ./test.cppCR
plus the LF that’s supposed to be there (that bash excludes from consideration). So, g++ is looking for a file whose name is "./test.cppCR", which, of course, doesn’t exist.
So it says:
./test.cppCR: No such file or directory
But, because of what a carriage return is, this causes the : No such file or directory to overwrite the ./test.cpp, so : No such file or directory is all you see.