Linux Hello World

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 18832 Views - Last Post: 06 February 2009 - 12:20 AM Rate Topic: -----

#1 Israel  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 7
  • View blog
  • Posts: 818
  • Joined: 22-November 04

Linux Hello World

Posted 12 April 2006 - 01:57 PM

Ok, I've been wasting a lot of time trying to get linux wireless and learning the basics, I'm just now getting around to hello world :( But anyway, here's the code I found online:
#include <iostream>

using namespace std;

int main()
{
          cout<<"Hello Linux!\n";
          cin.get();
}



And here's the errors I"m getting:
/tmp/ccSbfEGk.o: In function `main':Linux.cpp:(.text+0x25): undefined reference                                            to `std::cout'
:Linux.cpp:(.text+0x2a): undefined reference to `std::basic_ostream<char, std::c                                           har_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream                                           <char, std::char_traits<char> >&, char const*)'
:Linux.cpp:(.text+0x35): undefined reference to `std::cin'
:Linux.cpp:(.text+0x3a): undefined reference to `std::basic_istream<char, std::c                                           har_traits<char> >::get()'
/tmp/ccSbfEGk.o: In function `__tcf_0':Linux.cpp:(.text+0x57): undefined referen                                           ce to `std::ios_base::Init::~Init()'
/tmp/ccSbfEGk.o: In function `__static_initialization_and_destruction_0(int, int                                           )':Linux.cpp:(.text+0x84): undefined reference to `std::ios_base::Init::Init()'
/tmp/ccSbfEGk.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status



Is This A Good Question/Topic? 0
  • +

Replies To: Linux Hello World

#2 Nova Dragoon  Icon User is offline

  • The Innocent Shall Suffer, Big Time
  • member icon

Reputation: 36
  • View blog
  • Posts: 6,169
  • Joined: 16-August 01

Re: Linux Hello World

Posted 12 April 2006 - 04:01 PM

whats your compile line?

g++ code.cpp


should work
Was This Post Helpful? 0
  • +
  • -

#3 Israel  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 7
  • View blog
  • Posts: 818
  • Joined: 22-November 04

Re: Linux Hello World

Posted 13 April 2006 - 11:02 AM

Quote

root@1[C++]# gcc Linux.cpp -o Linux.cpp
/tmp/ccxyuHt1.o: In function `main':Linux.cpp:(.text+0x25): undefined reference to `std::cout'
:Linux.cpp:(.text+0x2a): 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*)'
:Linux.cpp:(.text+0x35): undefined reference to `std::cin'
:Linux.cpp:(.text+0x3a): undefined reference to `std::basic_istream<char, std::char_traits<char> >::get()'
/tmp/ccxyuHt1.o: In function `__tcf_0':Linux.cpp:(.text+0x57): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccxyuHt1.o: In function `__static_initialization_and_destruction_0(int, int)':Linux.cpp:(.text+0x84): undefined reference to `std::ios_base::Init::Init()'
/tmp/ccxyuHt1.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status


Quote

root@1[C++]# g++ Linux.cpp -o Linux.cpp
g++: Linux.cpp: No such file or directory
g++: no input files


Quote

root@1[C++]# g++ /home/Israel/C++/Linux.cpp -o
g++: /home/Israel/C++/Linux.cpp: No such file or directory
g++: no input files

This post has been edited by Dark_Nexus: 19 April 2006 - 12:45 AM

Was This Post Helpful? 0
  • +
  • -

#4 Nova Dragoon  Icon User is offline

  • The Innocent Shall Suffer, Big Time
  • member icon

Reputation: 36
  • View blog
  • Posts: 6,169
  • Joined: 16-August 01

Re: Linux Hello World

Posted 13 April 2006 - 11:07 AM

yoour first gcc line tried to output to the source, possibly destroying it


g++ compile lines should be

g++ source.cpp -o source
Was This Post Helpful? 0
  • +
  • -

#5 Israel  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 7
  • View blog
  • Posts: 818
  • Joined: 22-November 04

Re: Linux Hello World

Posted 13 April 2006 - 11:18 AM

I'm still confused, like this?

root@1[C++]# g++ Linux.cpp -o /home/Israel/C++/Linux.cpp
g++: Linux.cpp: No such file or directory
g++: no input files



I know you said my source may have been destroyed but I don't think that quite have the correct syntax.
Was This Post Helpful? 0
  • +
  • -

#6 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Linux Hello World

Posted 13 April 2006 - 11:23 AM

Go to the directory in which you have saved the source file (check and see if it is valid...otherwise you may have to re write and save it, and I advise against a name like linux.cpp...save it as test1.cpp). Then, from the command line in that directory, type the following:
g++ -o test1.cpp test1


This tells the compiler to compile the code located in source file test1.cpp into a file called test1 (you can name it anything).
then, to run it from the command line, in that same directory, type:
./test1


this should execute the program.
Was This Post Helpful? 0
  • +
  • -

#7 Israel  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 7
  • View blog
  • Posts: 818
  • Joined: 22-November 04

Re: Linux Hello World

Posted 13 April 2006 - 11:42 AM

No luck...?

Israel@4[~]$ cd /home/Israel/C++
Israel@4[C++]$ g++ -o test1.cpp test1
test1: file not recognized: File format not recognized
collect2: ld returned 1 exit status
Israel@4[C++]$ g++ test1.cpp -o test1
g++: test1.cpp: No such file or directory
g++: no input files
Israel@4[C++]$ ./test1
bash: ./test1: Permission denied
Israel@4[C++]$ su
Password:
root@4[C++]# ./test1
bash: ./test1: Permission denied
root@4[C++]# g++ -o test1.cpp test1
test1: file not recognized: File format not recognized
collect2: ld returned 1 exit status
root@4[C++]# g++ test1.cpp -o test1
g++: test1.cpp: No such file or directory
g++: no input files
root@4[C++]#


Was This Post Helpful? 0
  • +
  • -

#8 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Linux Hello World

Posted 13 April 2006 - 12:03 PM

Sorry...it should be
g++ -o test1 test.cpp


I mistyped...
Was This Post Helpful? 0
  • +
  • -

#9 Jessehk  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 24
  • Joined: 06-January 06

Re: Linux Hello World

Posted 15 April 2006 - 12:18 PM

Ok, I'm going to make this really easy for you. :)

1) type in the following:

#include <iostream>

int main() {
    std::cout << "Hello, world!" << std::endl;

    return 0;
}




Save it as hello.cpp

2) enter the following in a terminal (in the same directory as the saved program):

g++ hello.cpp -o hello



3) Run the program like this:

./hello


This post has been edited by Jessehk: 15 April 2006 - 12:38 PM

Was This Post Helpful? 1

#10 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Linux Hello World

Posted 15 April 2006 - 02:30 PM

Well, now that three of us have provided the same suggestion, I hope it works! :)
Was This Post Helpful? 0
  • +
  • -

#11 Israel  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 7
  • View blog
  • Posts: 818
  • Joined: 22-November 04

Re: Linux Hello World

Posted 16 April 2006 - 06:50 AM

Got it! Thanks! :D

This post has been edited by Israel: 16 April 2006 - 06:55 AM

Was This Post Helpful? 0
  • +
  • -

#12 <binary_glitch>  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 47
  • Joined: 27-November 08

Re: Linux Hello World

Posted 05 February 2009 - 03:02 AM

I know what happened! He was enterign the corecry gcc comlile scripts from the get go, he wrote a typical ms windows style hello world and used
 
#include <iostream>
Using namespace std;
int main() 
{
cout << "Hello, world!" << 
cin.get();
}
 


Instead of

#include <iostream>

int main() 
{
std::cout << "Hello, world!" << std::endl;
return 0;
}



Notice how he handels the std namespace and how he closes. The former is typical for win students, where as the later conforms better to *nix systems, idk why, idk much about it at all except that I assumed the general syntax of c++ would be differnt for linux than windows and I don't do windows but most pprole do so it was safe for me to assume that most c++ tutorials would assume win syntax and not even bother to mention that this code isn't quite the same for uniz like systems, armed with that educated guess before I even attemped to learn c++ (on a linux machine) I made sure I was getting the right syntax for my educational example code, btw, if anyone knows a web address that has a c++ tutorial that teaches from beginner (hello world) to atleast intermediate or even advanced in linux syntax, please let me know because I got a book geared tward windows and I'm jus going through it lesson by lesson, except when I get to code I try my best to google an appropriate (linux style) equivelant.
Was This Post Helpful? 1
  • +
  • -

#13 no2pencil  Icon User is offline

  • Dic Head
  • member icon

Reputation: 5167
  • View blog
  • Posts: 26,849
  • Joined: 10-May 07

Re: Linux Hello World

Posted 05 February 2009 - 03:06 AM

<binary_glitch>, thank you for your contribution to the conversation, but this topic is over 2 years old!

:)

View Post<binary_glitch>, on 5 Feb, 2009 - 04:02 AM, said:

The former is typical for win students, where as the later conforms better to *nix systems, idk why, idk much about it at all


It's not a Windows vs Linux issue with the code.
Was This Post Helpful? 0
  • +
  • -

#14 Plus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 41
  • View blog
  • Posts: 414
  • Joined: 24-November 08

Re: Linux Hello World

Posted 05 February 2009 - 03:58 AM

:: Hello World Code ...

:: Linux Version,
#include <iostream>
using namespace std;

int main(){
		  cout<<"Hello Linux!\n";
		  cin.getch();
}


:: Windows Version,
#include <iostream>
using namespace std;

int main(){
		  cout<<"Hello Linux!\n";
		  system("pause");
}


Was This Post Helpful? 0
  • +
  • -

#15 <binary_glitch>  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 47
  • Joined: 27-November 08

Re: Linux Hello World

Posted 06 February 2009 - 12:16 AM

Well I'm sorry for reviving a dead issue... I guess? However it was relevent to a google search I was conducting, I noticed it and noticed that the URL lead to DIC a forum of which I am a member and so it peaked my interest so I decided to check it out, and I posted what I'm in the process of learning in hopes that it would help someone out. I don't have internet access except on my BlackBerry so I didn't see the date, sorry I didn't know how old it was. At any rate, I am still trying to find a web tutorial and or book that is designed to teach absolute beginners to code in c++ on linux, not windows. I don't know what words to use though, as programming languages are called 'languagea' I assume linguistic terminology would be approperate, but I'm no linguist, hence I don't know the slight shades of differnce between words like syntax, and dialect. So what do you call the minor differnces between how you code for windows vs how you code for linux? I just want to learn c++ but when I enter code from my book all I get is compiler errors and I can't work them out to save my life, then I go to my buddies google and alta vista and sake them if they know of a 'linux simple calculator sorce' or something to that effect and they usualy give me an assortment of code to choose from and out of that I can usualy find code with a lot of the same... um ... code parts? Idk what to call it? You know like #include <some_lib> and main () and int and double, etc what do you call strings, and variables, and functions, and devlorations, etc collectivly? Is there a word that generaly encompasses all that? How do I even ask when I don't know the words... ? At any rate, I'll just call it 'code parts' for now, okay so basically I'm telling you what I go through to get a single lesson, then I'm gonna ask if anyone has any suggestions on how I can less work getting lessons and more work learning them. This is what I go through; I get my BlackBerry, and my c++ book, turn on my machine, open my IDE, a terminal, and a text editor, then I try the lesson I'm on from the book, click compile and cross my fingers, if it works good, I jump from my chair and scream YES! If not I check out put, yet to make errors go away, checking to see that all simi colens are right etc, line numbers is usualy part of my out put so that helps, if nothing after an hour or so of trying I go to the net (on my phone as I haven't options) and search for code that works and uses a lot of the same code parts and then I complile and pray, if it doesn't work after and hour or so of trying then repeat. Anyone got anything more edfficent to the learning process? Here's what I have to my disposal. A local library that provides books (limited programming books) and internet (downloading is not alowed) and I have a computer with linix kernel 2.6.x (zenwalk, debian, DSL, SystemRescueCD, and Backpack Programmer's LiveCD Linux) all but the first two are live CD's. I have internet on my BlackBerry Pearl, and like 1 to 4 hours a day to devote, sorry I have kids and a full-time-job. I have no brodband, no money, and little time, but I have patients, passion, and determination!
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2