my first C++ program, errors while compiling
I'm looking for an answer for the following problem (very difficult against all appearances):
How to compile and run my first C++ program?. Here is the code (very original..): #include<iostream> int main() { std::cout << "Hello World!" << std::endl; return 0; } I run it by writing: gcc hello.cpp Here are the errors: /home/staszek/tmp/ccJZcrMe.o(.text+0x14): In function `main': : undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)' /home/staszek/tmp/ccJZcrMe.o(.text+0x21): In function `main': : undefined reference to `std::cout' /home/staszek/tmp/ccJZcrMe.o(.text+0x26): In function `main': : undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' /home/staszek/tmp/ccJZcrMe.o(.text+0x2f): In function `main': : undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))' /home/staszek/tmp/ccJZcrMe.o(.text+0x5c): In function `__static_initialization_and_destruction_0(int, int)': : undefined reference to `std::ios_base::Init::Init[in-charge]()' /home/staszek/tmp/ccJZcrMe.o(.text+0x8b): In function `__tcf_0': : undefined reference to `std::ios_base::Init::~Init [in-charge]()' /home/staszek/tmp/ccJZcrMe.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status I use Mandrake 10.0 and?... Well, I'd just like someone to answer. |
i think "g++" if it's a c++ program. you might also want to specify the file it will make with the "-o" option.
|
I've got it. That wasn't so difficult, was it?.
Now I'd like to link it and make it a runnable program. Do I have to do it on my own or maybe there is a person who would be willing to give me some hints?. |
what do you mean? are you saying you want to only have to type "hello" at the commandline in any directory for it to work? like having it as an actual program on your computer?
|
Ay, Ay.
|
Yes, that's exactly what I want.
|
I've just went through g++ man and still cannot find it.
I think it must be some problem with linking. |
i think "link" or "symlink" will work with that, but you've gotta play around with it. i don't really know where you would link it to though (what directory).
|
It should already be linked into an executable, but if you don't have . (current directory) in your path then you have to tell your shell where to find it. For example, try typing: ./hello
|
How to make my shell find the right directory with executable file in C++?.
I have compiled my hello.cpp program and I'd like to know where to find executable (if it's been created).
I have compiled it with 'g++ -o hello.cpp' command. I've got hello.o in my current directory but there's no executable there. Where could I find executable?. |
you have to say the name you want after the -o, then the .cpp file. for example, if i wanted to compile hello.cpp and make an executable out of it called "hello", i would do this:
g++ -o hello hello.cpp the newly created "hello" executable file will be in the same directory after the compile is through. execute it by typing hello and that's it. |
Thanks
Thank you all for posting.
|
All times are GMT -5. The time now is 08:15 PM. |