-
help with gcc
Ive been programming in c++ for a while and when i swiched to linux i didnt like any of the programming interfaces, so i wanted to learn to do it in command line. I cannot get ANY programs to work with ANYTHING on linux in C++. Please help!!!!
(yes i know i am a newbie)
-
The command you need is
gcc <source file> -o (output file)
To run the compiled file the command is
./<filename>
Don't forget the "./". I do not believe Linux will check the default directory for the filename you specify. You have to tell it where to look, unless it's specified in your path. I know RedHat does that.
-
To compile C++ programs under Linux, usually you can do so with gcc. From the command line, just type "gcc <program name>" (without the quotes of course). If you need other compilation options, check out the man page, "man gcc".
Hope this helps,
alpha
-
-
its for some reason coming up w/ a compile error ive never seen before... Whats wrong with this source:
#include <iostream.h>
int main()
{
cout << "Hello, World!";
return 0;
}
-
A little more detail here might help. You're basically asking us to fix a leaky basement without telling us where the leak is.
What errors are you getting?
-
ummm... what's the error??
-
the errors are as follows:
undefined refrence to "std::cout"
undefined refrence to "std::basic_ostream <a bunch of vars passed through this arg.>
undefined refrence to "std::iso_base::Init::~Init [in-charge]()"
undefined refrence to "__gxx_personality_v0"
and then it says:
collect2: ld returned 1 exit status
-
Try including the line
using namespace std;
Your code would look like this:
#include <iostream.h>
using namespace std;
int main()
{
cout << "Hello, World!";
return 0;
}
You haven't defined a nemaspace which includes the cout stream yet.
Hope this helps.
/edit
Some compilers add namespaces by default if you don't tell them to. The Gnu C compiler doens't, but it's free, so I never complain about it.
/edit
-
Striek:
i just tried that... no luck.
-
Hmmm...
Maybe, instead of "include <iostream.h>" , try just "include <iostream>"
C++ at one point did away with the old header files. I'm not sure exactly why, but the new way is faster.
-
Striek:
I already tried that(that was my first idea before <iostream.h>
-
The last thing I can think of is to change all of the references to cout to specify the standard library, so change them to std::cout. I think gcc before version 3 enforced this.
-
that didnt work either...
would the problem be in the include librarys???
the only reason i dont think this is the problem is because when i tried the program:
#include <iostream.h>
int main()
{
cout <<"Hello, World!";
return 0;
}
:it came with an error with "std::cout" so i think it read it ok...
hmmmm.........
would reinstalling fix the prob.?
-
it looks like it is not locating the iostream.h you need to do a locate and find the iostream.h and then include it explicitly... I believe it is like... #include "/usr/local/include/iostream.h" but I haven't done it in so long I don't remember now... there is a way to change the include paths in the complier, but I don't have any clue how to do that.
-
I think ive found the problem... /usr/local/include exists but there is nothing in it... does anyone know where another include path is?
-
i downloaded new header files and it works fine now...