Page 1 of 1

Programming problems!!!

PostPosted: Thu Oct 16, 2008 8:59 pm
by Theo9909
I'm trying to compile a program in terminal. I have a script that has worked for ten years and I can't get it to work in 1.9 here is the script code

#!/bin/bash

#

echo "...Compiling C++ Program "$1"..."



g++ -Wall -time -Wno-deprecated -o object $1

rc=$?

echo "...Compilation for $0 Completed with RC=$?..."

if [ $rc -eq 0 ]; then

cp object $1.object

fi


exit 0

there are twelve lines of code here. Yet it gives me this error:

porsche@porsche-laptop:~$ bash cplus newfile.cc
...Compiling C++ Program newfile.cc...
: command not found
: No such file or directory
g++: no input files
...Compilation for cplus Completed with RC=0...
cplus: line 13: syntax error: unexpected end of file



the code source is in my homefolder, yet nothing works. any help would be great! Thanks!!!

Re: Programming problems!!!

PostPosted: Fri Oct 24, 2008 12:20 pm
by tuxsax
I don't know squat about C programming, but once I had a similar problem with a script, I think it was in perl or bash, can't remember, anyway, what solved me the problem was actually removing the last empty line, if your 12 lines of codes end at "exit 0" then let it be the last line, don't leave a blank line after it.

Ziv

Re: Programming problems!!!

PostPosted: Fri Oct 24, 2008 7:27 pm
by red_team316
I also have had an odd problem once with newlines at the end of a file, can't say it was C based though...

Are you sure g++ is installed and/or cpp? It may be a simple question but the first line that appears to be going wrong is that it cannot find g++. Other than that, g++ will report "g++: no input files" if your path is incorrect or missing. Try using full paths, it's possible that you are trying to use a relative path and just not working right.

***Moved topic to programming***

Re: Programming problems!!!

PostPosted: Mon Oct 27, 2008 4:12 pm
by TheeMahn
Theo9909 wrote:I'm trying to compile a program in terminal. I have a script that has worked for ten years and I can't get it to work in 1.9 here is the script code

#!/bin/bash

#

echo "...Compiling C++ Program "$1"..."



g++ -Wall -time -Wno-deprecated -o object $1

rc=$?

echo "...Compilation for $0 Completed with RC=$?..."

if [ $rc -eq 0 ]; then

cp object $1.object

fi


exit 0

there are twelve lines of code here. Yet it gives me this error:

porsche@porsche-laptop:~$ bash cplus newfile.cc
...Compiling C++ Program newfile.cc...
: command not found
: No such file or directory
g++: no input files
...Compilation for cplus Completed with RC=0...
cplus: line 13: syntax error: unexpected end of file



the code source is in my homefolder, yet nothing works. any help would be great! Thanks!!!


First I would make sure "build essential" is installed:
Code: Select all
sudo apt-get install build-essential

I have taken your script and droped it on my desktop as follows:
Code: Select all
theemahn@SledgeHammer:~/Desktop$ cat test.sh
#!/bin/bash
#
echo "...Compiling C++ Program "$1"..."
g++ -Wall -time -Wno-deprecated -o object $1
rc=$?
echo "...Compilation for $0 Completed with RC=$?..."
if [ $rc -eq 0 ]; then
cp object $1.object
fi
#exit 0 unnecessary
theemahn@SledgeHammer:~/Desktop$


Wrote a simple c++ program:
Code: Select all
theemahn@SledgeHammer:~/Desktop$ cat test.cpp
// my first program in C++

#include <iostream>
using namespace std;

int main ()
{
  cout << "Hello World!";
  return 0;
}

theemahn@SledgeHammer:~/Desktop$

and compiled it:
Code: Select all
theemahn@SledgeHammer:~/Desktop$ ./test.sh test.cpp
...Compiling C++ Program test.cpp...
# cc1plus 0.16 0.01
# as 0.00 0.00
# collect2 0.05 0.00
...Compilation for ./test.sh Completed with RC=0...
theemahn@SledgeHammer:~/Desktop$