Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
6Activity
0 of .
Results for:
No results containing your search query
P. 1
Programming languages by example

Programming languages by example

Ratings: (0)|Views: 333 |Likes:
Published by Hany Kheir
The programming languages that have compilers operating under Linux OS and will be covered in this article are: C++, fortran77, gfortran, pascal (free pascal compiler), SmallEiffel, ADA, Haskell, Ocaml and Java. Example programs linking with the following graphical libraries will also be presented: gtkmm, OSG and free GLUT.
The programming languages that have compilers operating under Linux OS and will be covered in this article are: C++, fortran77, gfortran, pascal (free pascal compiler), SmallEiffel, ADA, Haskell, Ocaml and Java. Example programs linking with the following graphical libraries will also be presented: gtkmm, OSG and free GLUT.

More info:

Published by: Hany Kheir on Oct 02, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as ODT, PDF, TXT or read online from Scribd
See more
See less

01/30/2013

pdf

text

original

 
Programming languages by example
Introduction:The programming languages that have compilers operating under Linux OS (we shall be concernedhere with openSuse and/or simplyMEPIS VERSION 6.5 or 7.0) and will be covered here in this articleare: C++, fortran77, gfortran, pascal (free pascal compiler), SmallEiffel, ADA, Haskell, Ocaml andJava. Example programs linking with the following graphical libraries will also be presented: gtkmm,OSG and free GLUT.
 
LanguageCommand linecompiling command orstatementExampleCompiler type &versionC++ (GNU,gcc)g++ g++ hellocpp.cpp -o hello1 gcc v. 4.0.3fortran77(GNU, gcc)g77 g77 -o hellog77 hello.for gcc v. 3.4.6gfortran (GNU,GCC)gfortran gfortran -o hellogfor hello.for gcc v. 4.0.3pascal (freepascal)fpc fpc hello.pas v. 2.2.0SmallEiffel(GNU)compile compile hello.e -o hellosegnu eiffelcompiler release0.74HASKELL(GHC)ghc ghc -- make -o hellohaskell hello.hs v. 6.4.1ADA (GNU,gcc)gcc then gnatblgcc -c helloada.adb then gnatbl -o hello2helloada.aligcc v. 4.0.3OCaml ocamloptocamlopt -c amodule.ml, ocamlopt -cbmodule.ml, ocamlopt -o helloocamodule.cmx bmodule.cmxversion 3.10.2Java javacjavac helloj.java, to run type java + theclass name (eg. HelloClassApp)JDK, version"1.5.0_13"Let's get graphical:For example, GTK+ is a highly usable, toolkit for creating graphical user interfaces(GUI) which boasts cross platform compatibility and an easy to use API. GTK+ it is written in C, buthas bindings to many other popular programming languages such as C++, Perl, Python and C# amongothers. GTKMM is the wrapper for C++ language (a library used to create graphical userinterfaces).gtkmm speaks arabic.GTKMM programs can be compiled and run under Windowsoperating system. To do so, you may follow the steps given hereafter:1. Download and install MingW.2. Download and install Dev-Cpp.3. Download and unzip GTK library under c:\MingW.4. Download and install gtkmm library under c:\Dev-Cpp.5. Download and install msys.6. Copy the source code into /home/user_name/ directory of C:\msys.
 
7. Compile source code, example for command line compiling statements in msys window:
export PKG_CONFIG_PATH=c:/Dev-Cpp/gtkmm/pkgconfig
g++ 'pkg-config --cflags gtkmm-2.4' example.cc -o example 'pkg-config --libs gtkmm-2.4'8. Run executable (.exe) Windows fileLibraryCommand line compilingcommand or statementExampleCompiler type &versiongtkmm g++g++ gtkmareas.cc -o gtkmareas `pkg-configgtkmm-2.4 --cflags --libs`g++ (GCC) 4.2.1There are certain libraries that are written for example in C (or C++) that can be added to themicrocomputer hard drve. With these libraries and the appropriate compiler, eg. C compiler, linking tosuch libraries and compiling your source, you can produce an output file (2D or 3D graphics one).Examples for such libraries are Cairo and OpenSceneGraphics (OSG).LibraryCommand linecompilingcommand orstatementExampleCompiler type& versioncairo cccc -o hellocairo $(pkg-config --cflags --libscairo) hellocairo.ccc (GCC)4.2.1OpenSceneGraph(OSG)g++g++ -c HelloMain.cpp, g++ -c HelloSG.cpp,g++ -o hello HelloSG.o HelloMain.o-I/usr/include -losg -losgDB -losgUtil-losgViewer -losgTextg++ (GCC)4.2.1Free GL utilitytoolkit (GLUT)gccgcc -o helloglut helloglut.c -lm -lGL -lGLU-lglutgcc (GCC)4.2.1General:1. Make a new directory under /home/user-name (eg. hany)/Documents and call it executables.2. Add to this directory each executable (compiled) file.3. Go to the desktop, click Documents (Konquerer will open with a list of files & folders plus themenu and probably a tree-like files & folders on your PC), click View on the main menu andthen choose Show hidden files. The hidden files that start with a dot (.) will appear.4. Go to /home/user-name (eg.han)y/ directory and click on .bashrc file. It will open in a texteditor, probably kwrite. Add the following line to the end of the file export PATH=/home/user-name (eg.hany)/Documents/executables:$PATH. Then save the file and cose (exit) the editor.5. Go to konquerer, click View in the menu list, then choose and click one more time Show hiddenfiles, the hidden ones will disappear.Saying hello in different languages:
C++:
 1. Open a new document in any text editor (kwrite, kedit or kate).2. Type the following lines:#include <stdio.h>int main ()
 
{printf ("Hello world from gcc/g++\n");}3. Save the file as hellocpp.cpp4. Compile it per the above table5. Copy the executable (compiled) file to the executables folder (directory), eg. hello16. Open the konsole window and run hello1 (i.e. type hello1 at the prompt).
Fortran 77:
1. Open a new document in any text editor (kwrite, kedit or kate).2. Type the following lines:program helloc This program prints hello, leave at least 7 spaces before typing program hello abovewrite (*, *) 'hello from g77, fortran77'stopend3. Save the file as hello.for4. Compile it per the above table5. Copy the executable (compiled) file to the executables folder (directory), eg. hellog776. Open the konsole window and run hellog77 (i.e. type hellog77 at the prompt).
gFortran:
1. Open a new document in any text editor (kwrite, kedit or kate).2. Type the following lines:program helloc This program prints hello, leave at least 7 spaces before typing program hello abovewrite (*, *) 'hello from g77, fortran77'stopend3. Save the file as hello.for4. Compile it per the above table5. Copy the executable (compiled) file to the executables folder (directory), eg. hellogfor6. Open the konsole window and run hellogfor (i.e. type hellogfor at the prompt).
Pascal:
1. Open a new document in any text editor (kwrite, kedit or kate) or open a trminal (konsole)window and type fp to open the FreePascal IDE for Linux.2. Type the following lines:program hello;beginwriteln('hello from pascal');end.3. Save the file as hello.pas4. Compile it per the above table5. Copy the executable (compiled) file to the executables folder (directory), eg. hello6. Open the konsole window and run hello (i.e. type hello at the prompt).

Activity (6)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
charzree liked this
Chandan Sharma liked this
intechh liked this
MR_AQK liked this

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->