Difference between revisions of "HelloWorld"

From Gumstix User Wiki
Jump to: navigation, search
(remove spam)
 
Line 1: Line 1:
----
 
<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;">
 
----
 
=[http://uvetysudema.co.cc Under Construction! Please Visit Reserve Page. Page Will Be Available Shortly]=
 
----
 
=[http://uvetysudema.co.cc CLICK HERE]=
 
----
 
</div>
 
 
This page will provide sample code for writing, compiling, and running HelloWorld in Python and C++ on your Overo COM. To do this it will be assumed you have Console access to your Overo.
 
This page will provide sample code for writing, compiling, and running HelloWorld in Python and C++ on your Overo COM. To do this it will be assumed you have Console access to your Overo.
  
Line 14: Line 6:
 
This command opens a text editor nano, which allows you to edit the text in files. In this specific case, it is opening the file HelloWorld.py. If this file has existed before, it would have opened the existing file. However, since it did not, nano opens a new text file with if saved, will be saved as HelloWorld.py.
 
This command opens a text editor nano, which allows you to edit the text in files. In this specific case, it is opening the file HelloWorld.py. If this file has existed before, it would have opened the existing file. However, since it did not, nano opens a new text file with if saved, will be saved as HelloWorld.py.
 
Write the following code in the file:
 
Write the following code in the file:
  print &quot;Hello, Gumstix!&quot;
+
  print "Hello, Gumstix!"
To write the file (save it) press: &lt;br&gt;
+
To write the file (save it) press: <br>
Ctrl + O &lt;br&gt;
+
Ctrl + O <br>
Then to quit back to the command line, press: &lt;br&gt;
+
Then to quit back to the command line, press: <br>
Ctrl + X &lt;br&gt;
+
Ctrl + X <br>
 
And finally, issue this command to run the program:
 
And finally, issue this command to run the program:
 
  python HelloWorld.py
 
  python HelloWorld.py
Line 36: Line 28:
 
  nano HelloWorld.cpp
 
  nano HelloWorld.cpp
 
Once in the file, copy the following code to make HelloWorld in C++
 
Once in the file, copy the following code to make HelloWorld in C++
  #include &lt;iostream&gt;
+
  #include <iostream>
 
  using namespace std;
 
  using namespace std;
 
  int main () {
 
  int main () {
       cout &lt;&lt; &quot;Gumstix runs on C++&quot; &lt;&lt; endl;
+
       cout << "Gumstix runs on C++" << endl;
 
       return 0;
 
       return 0;
 
  }
 
  }
Then write the file and exit back to the command line with: &lt;br&gt;
+
Then write the file and exit back to the command line with: <br>
 
Ctrl + O
 
Ctrl + O
 
Ctrl + X
 
Ctrl + X
Line 51: Line 43:
 
Then, run the program using the command:
 
Then, run the program using the command:
 
  ./HelloWorld
 
  ./HelloWorld
This tells the computer to execute a file named HelloWorld located in the current directory (./). The outputs should be: &lt;br&gt;
+
This tells the computer to execute a file named HelloWorld located in the current directory (./). The outputs should be: <br>
 
  Gumstix runs on C++
 
  Gumstix runs on C++
 
Congratulations! You have successfully written your first C++ program on your Overo COM!
 
Congratulations! You have successfully written your first C++ program on your Overo COM!
Line 72: Line 64:
 
  nano HelloWorld.c
 
  nano HelloWorld.c
 
Once in the file, copy the following code to make HelloWorld in C
 
Once in the file, copy the following code to make HelloWorld in C
  #include &lt;stdio.h&gt;
+
  #include <stdio.h>
 
  int main () {
 
  int main () {
  printf(&quot;Gumstix runs on C\n&quot;);
+
  printf("Gumstix runs on C\n");
 
  return 0;
 
  return 0;
 
  }
 
  }
Then write the file and exit back to the command line with: &lt;br&gt;
+
Then write the file and exit back to the command line with: <br>
 
Ctrl + O
 
Ctrl + O
 
Ctrl + X
 
Ctrl + X
Line 86: Line 78:
 
Then, run the program using the command:
 
Then, run the program using the command:
 
  ./HelloWorld
 
  ./HelloWorld
This tells the computer to execute a file named HelloWorld located in the current directory (./). The outputs should be: &lt;br&gt;
+
This tells the computer to execute a file named HelloWorld located in the current directory (./). The outputs should be: <br>
 
  Gumstix runs on C
 
  Gumstix runs on C
 
Congratulations! You have successfully written your first C program on your Overo COM!
 
Congratulations! You have successfully written your first C program on your Overo COM!

Latest revision as of 16:48, 23 November 2010

This page will provide sample code for writing, compiling, and running HelloWorld in Python and C++ on your Overo COM. To do this it will be assumed you have Console access to your Overo.

Python

To start writing HelloWorld in Python, issue the following command

nano HelloWorld.py

This command opens a text editor nano, which allows you to edit the text in files. In this specific case, it is opening the file HelloWorld.py. If this file has existed before, it would have opened the existing file. However, since it did not, nano opens a new text file with if saved, will be saved as HelloWorld.py. Write the following code in the file:

print "Hello, Gumstix!"

To write the file (save it) press:
Ctrl + O
Then to quit back to the command line, press:
Ctrl + X
And finally, issue this command to run the program:

python HelloWorld.py

The program should output:

Hello Gumstix! 

Congratulations! You have programmed your first Python program on your Overo. You may re-open HelloWorld.py using the nano command to change the outgoing text to whatever you would like.

C++

C and C++ code requires compilation which can be done natively---on the Gumstix itself---or on a development machine using a cross-compiler. To do native compilation, you need to install a compiler as well as any required libraries. You'll need to be booting from a microSD card as this installation takes approximately 75MB of space.

opkg update
opkg install task-native-sdk

NOTE: Installing task-native-sdk can take 45 minutes to two hours. To do this you will need an active internet connection on your Overo COM


Once you have an environment that is capable of compiling and executing a C++ file, you need to write the file. First, lets write a C++ file. To open a text editor, issue the command:

nano HelloWorld.cpp

Once in the file, copy the following code to make HelloWorld in C++

#include <iostream>
using namespace std;
int main () {
     cout << "Gumstix runs on C++" << endl;
     return 0;
}

Then write the file and exit back to the command line with:
Ctrl + O Ctrl + X

Next, to compile the program, issue the command:

g++ -o HelloWorld HelloWorld.cpp

This creates an executable object (HelloWorld) by using the g++ compiler on the C++ file HelloWorld.cpp. Then, run the program using the command:

./HelloWorld

This tells the computer to execute a file named HelloWorld located in the current directory (./). The outputs should be:

Gumstix runs on C++

Congratulations! You have successfully written your first C++ program on your Overo COM!

C

Since C is very similar to C++, the following instructions will be very similar to the C++ instructions. If you have already followed the instructions The differences are:

  1. HelloWorld.cpp becomes HelloWorld.c
  2. The code is different
  3. g++ becomes gcc

The rest is the same. Below is the exact same instructions, just modified for writing, compiling and executing a C file.

C and C++ code requires compilation which can be done natively---on the Gumstix itself---or on a development machine using a cross-compiler. To do native compilation, you need to install a compiler as well as any required libraries. You'll need to be booting from a microSD card as this installation takes approximately 75MB of space.

opkg update
opkg install task-native-sdk

NOTE: Installing task-native-sdk can take 45 minutes to two hours. To do this you will need an active internet connection on your Overo COM


Once you have an environment that is capable of compiling and executing a C file, you need to write the file. First, lets write a C file. To open a text editor, issue the command:

nano HelloWorld.c

Once in the file, copy the following code to make HelloWorld in C

#include <stdio.h>
int main () {
	printf("Gumstix runs on C\n");
	return 0;
}

Then write the file and exit back to the command line with:
Ctrl + O Ctrl + X

Next, to compile the program, issue the command:

gcc -o HelloWorld HelloWorld.c

This creates an executable object (HelloWorld) by using the gcc compiler on the C file HelloWorld.c. Then, run the program using the command:

./HelloWorld

This tells the computer to execute a file named HelloWorld located in the current directory (./). The outputs should be:

Gumstix runs on C

Congratulations! You have successfully written your first C program on your Overo COM!