Click to See Complete Forum and Search --> : Not able to compile simpel Perl/C++
JockVSJock
03-28-2002, 08:16 AM
I've created just simple Perl/C++ programs that I can easily compile on my windows box, but yet I can't get them to do anything on my Linux box.
Is this something to do with my kernel. I believe that when I installed Linux, I didn't install the kernel, cause if I do a insmod or modprobe command I get the 'command not found' error?
please help.
thanks
-Chris
bwkaz
03-28-2002, 09:53 AM
Well I have no idea how Perl and C++ interface with each other, but I can tell you that your problem is most definitely not that you didn't install a kernel. Had you not installed a kernel, your machine would do exactly nothing when you booted (or after you chose linux off your bootloader, if you dual-boot). There's a kernel there.
As for modprobe and insmod, there are a couple possibilities. Either you didn't install modutils (highly, highly unlikely, because many distros use a highly modular kernel, that's how they adapt themselves to people's hardware), or you aren't logged in as root (try to su before using modprobe), or even as root, /sbin isn't in your PATH environment variable (instead of typing modprobe, try /sbin/modprobe). If logging in as root and telling the shell where modprobe is both don't work, then install modutils.
However, modprobe is almost guaranteed to not be your problem with the Perl/C++ stuff. Perl and C++, as long as a kernel is running, don't care for the most part what's enabled in it (via modules). As long as there's a C++ compiler and a Perl interpreter installed, it should work -- check for those. The package names are probably gcc-g++-<version> (or something) and perl-<version>.
How are you trying to run the programs?
did you install perl and the c++ compiler on your linux box?
try the following at the command line:
'which perl'
'which g++'
if they don't return paths, then you haven't installed them.
JockVSJock
03-29-2002, 10:42 AM
When I do a which gcc and which perl I get the following output
which gcc
/usr/bin/gcc
which perl
/usr/bin/perl
and lnn /usr/bin/foo gives me all of the packages that are installed for each software package.
Here is a simple gcc that I can do on my windows box
//checking to see if gcc is working
#include<iostream.h>
int main()
{
cout<<"Hello World";
return 0;
}
When compiling I get the following output:
./hello.cpp: //Checking: No such file or directory
./hello.cpp: line 8: syntax error near unexpecte token 'main()'
./hello.cpp: line 8: 'int main()'
any ideas on this one?
thanks
-Chris
Stuka
03-29-2002, 10:45 AM
Two quick thoughts -
1. What was your command line? (I don't think that's the issue, but ya never know!).
2. Is there a space between the #include and the <iostream.h>? If not, it's probably messing up cpp (the preprocessor) which ends up really fragging gcc.
Ben Briggs
03-29-2002, 04:12 PM
Also, make sure you're using g++ not gcc, cause gcc is for C, not C++. :)
bwkaz
03-29-2002, 06:59 PM
Originally posted by Ben Briggs:
<STRONG>Also, make sure you're using g++ not gcc, cause gcc is for C, not C++. :)</STRONG>
And gcc does not recognize the C++ single-line commenting that you are using up at the top of this file. That's the reason behind your first error.
Not sure about the rest of them, though.
TheBouleOfFools
03-29-2002, 11:12 PM
You guys I think he's just pulling your legs... it's pretty damn funny though :D
Originally posted by Ben Briggs:
<STRONG>Also, make sure you're using g++ not gcc, cause gcc is for C, not C++. :)</STRONG>
Ben Briggs!!!
what up, dude. :)
JockVSJock
03-30-2002, 11:47 AM
Ok, so I've checked to see is I have gcc and g++ on this machine using the which command, and I do.
All of the c++ files that I have, have the .cpp extention and I have made them executibles, but they won't execute.
Do I need to add #!/usr/bin/g++ for my c++ programs and #!/usr/bin/perl for my perl program?
Any ideas?
Here is the simple Perl program that I created and it won't run as well...
#!/usr/bin/perl
# program name: Simple.p
print("This is a simple\n");
print("Perl program.\n");
I'm getting really frustrated with this. If I could get these little things to work out, I would cut all times from windows, but can't so I haven't yet, but I would love to.
thanks
-Chris
anshelm
03-30-2002, 12:56 PM
When you compile your .cpp files, what do you type at the prompt?
I copied the text you posted and typed:
$g++ -o hello hello.cpp
$hello
and it outputed the expected "Hello World" message (I might suggest "Hello World\n" so that your prompt starts on the next line).
g++ 3.0.4 compiles you c++ code just fine.
first, you don't need #!/usr/bin/g++ to for c++ programs. forget that.
Now; if you didn't use the '-o' option to specify the filename of the executable, it's probably named a.out. Do 'ls' to verify the file is in your directory. Try './a.out' (or './filename' if you made your own filename)... If it says you don't have permission to run it, do 'chmod u+x filename' to make it executable..
now, for perl.. I think the reason it may not be working is that you need to have a space between the #! and the path:
'#! /usr/bin/perl'. Try that. Note this file, too, must have execute permissions. 'chmod u+x scriptname' will make it executable for you. If it still doesn't work, try running 'perl scriptname', which explicitly runs the perl interpreter on the script.
Of course you're getting frustrated, that's called "learning". Don't give up, though; that's called "losing". :) And you don't want to lose this battle, because it's really one of the easier ones. Take care; keep trying, and have fun. :)
JockVSJock
03-30-2002, 08:23 PM
I do the following for g++:
$ g++ -o hello hello.cpp
hello.cpp:13: parse error before ';'
I am a semi-colon there...? Again this compiles fine under Window$
For the Perl program:
$ ./Simple.p
./Simple.p: line 5: syntax error near unexpected token 'simple\n")'
./Simple.p: line.5: 'print("This is a simple\n");'
Does Window$ have a Perl Compiler?
-Chris
okay, so both of you compilers are working. Just because something compiles in windows, that doesn't mean it will compile in linux.. different compilers may act differently. I can't help with compiler errors unless I actually see the code (or at least a few lines surrounding the line in question). Same goes for perl.
Yes, you can get perl for windows. Go to activestate.com, they should have everything you need.
Don't give up; if you've been programming a while, you should know that stupid syntax errors are common. That may be the case here, or it may be something else.
Again, show me the lines of code where you're getting the errors (including the surrounding lines), and it'll be much more likely that I can help you. And when you post your code, make sure you use the UBB "code" tags, so that your code looks like:
#include <iostream>
main() {
// this is inside a CODE tag, so the
// lines will be properly indented
}
The tags are simply the words "code" and "/code" surrounded in [ and ]. (You can also use the little "code" button below the edit box.
JockVSJock
03-31-2002, 03:06 PM
First thing, thanks everybody for taking the time to look at my code and trying to troubleshoot what I have, Linuxnewbie.org is truly one of the best Linux websites out there.
>Yes, you can get perl for windows. Go to >activestate.com, they should have everything >you need.
Ya, I found that Perl for Windows @ that website, but really, it is probably much more exciting to do this under Linux than Window$,.
>Don't give up; if you've been programming a >while, you should know that stupid syntax >errors are common. That may be the case >here, or it may be something else.
I've programmed in C++ for more than a year, or course only in school and now I am doing some stuff in C, Linux, AWK, SED, and Perl. Hoping to get more experience under my belt here, so I do this at work.
I'm not ready to give up...Here I'll post the G++ one first
/Checking to see if G++ works or not
//#!/usr/bin/g++
#include"iostream.h"
int main()
{
cout<<"Hello World ";
return 0;
}
And here is the G++ one
#! /usr/bin/perl
# program name: Simple.p
print("This is a simple\n");
print("Perl program.\n");
thanks
-Chris
anshelm
03-31-2002, 03:59 PM
After adding a '/' before the '/Checking', it compiled and ran correctly with g++ 2.96, g++ 3.0.1, and g++ 3.0.4.
Try this code:
//Checking to see if G++ works or not
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World\n";
return 0;
}
stuka mentioned above that you need to have a space between the #include and the "iostream.h". The code you posted doesn't have a space there, so try that.
I don't see anything wrong with the perl, I'll have to try it when I get to work tomorrow.
JockVSJock
03-31-2002, 10:41 PM
Thanks to all of you I got the G++ to work. Yes the learning curve is way more than doing this on a Windows machine, but man oh man, if you could see the smile on my face right now.
I didn't realize that I needed to do the following: g++ -o foo foo.cpp
and then I guess that creates an executible called foo and then ./foo . Cause if I go into that directory where foo.cpp is there is foo.
But my next question is for the Perl. I know the code is right cause I've taken straight from a textbook. Do I have to use the same type of commands to get that to compile as I did for G++? Cause the book doesn't say so and I know that I have Perl loaded on my machine.
thanks again and I need to get some sleep!!!
-Chris
Stuka
04-01-2002, 12:36 AM
perl doesn't get compiled. If you have a perl script named 'foo', you just run:
perl fooassuming perl is in your path (which it probably is - but this being windows you might need to check).
<edit>
got confused..too tired from Easter w/the family and fence-building...if you have the proper shebang line in Linux, you should be ok...
</edit>
[ 31 March 2002: Message edited by: Stuka ]
JockVSJock
04-01-2002, 10:52 PM
God, I feel like an idiot...
That worked, perl foo, executed the program.
But why in the hell wasn't this mentioned in my Linux textbook, 'Guide to UNIX Using Linux' by Dent/Gaddis, published by Course Technologies?
This would have at least saved me from posting this simple, stupid question on here.
thanks again to you all
-Chris
well, your method should have worked...