HelloWorld

From Gumstix User Wiki
Revision as of 09:18, 27 July 2010 by JustinC474 (Talk | contribs)

Jump to: navigation, search

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! in the command line. You may re-open HelloWorld.py using the nano command to change the outgoing text to whatever you would like.

C++

Assuming you have a C/C++ SDK installed on your Overo COM, then you are able to run C/C++ programs on your Overo. If you do not have a SDK installed, you may install one on your Overo COM with the following command (this is assuming you are in the Console window of your Overo):

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.

Assuming you have a C/C++ SDK installed on your Overo COM, then you are able to run C/C++ programs on your Overo. If you do not have a SDK installed, you may install one on your Overo COM with the following command (this is assuming you are in the Console window of your Overo):

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!