Back

Editing and Running the First Program at CERN

The goal of this workbook section is to show which are the tools and platforms available to edit, compile and run software applications.


Editing, compiling and running code on Unix

The most popular text editor available on the LXPLUS service is emacs.

Several guides on emacs are available: see for instance the reference card (web and pdf) or the emacs manual

Other available text editors are: pico, vi, xemacs, kedit, gedit

Exercise: Create the following simple C++ program using emacs. Then compile and run it.

The following will start emacs and create the file hello.cc if it doesn't already exist :

>emacs hello.cc 
Now enter and save the following simple program :
#include <iostream>
using namespace std;

int main()
{
  cout << "Hello, World\n";
  return 0;
}
Compile and run the program as follows :
>g++ hello.cc -o hello
>./hello
Hello, World
>

The purpose of covering this is to make sure you have a working C++ compiler and that you know how to turn a source code file into an executable file.


Compiling and running on Windows

Using a locally installed Visual Studio .NET compiler

In order to use the Visual Studio .NET environment that includes the C++ compiler you need to install it on your computer. On a CERN Nice registered computer you can install it by selecting Control Panel -> Add Programs -> Visual Studio .NET.


Editing, compiling and running code on Windows

Using the Visual Studio .NET GUI interface to edit, compile and run

  • Start -> All Programs -> Microsoft Visual Studio .NET 2003 -> Microsoft Visual Studio .NET 2003

  • File -> New -> Project -> Visual C++ Projects -> Win 32 Console Project

Then paste the follwing code in the .ccp source file window that opens:

#include "stdafx.h"

#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    cout << "Hello, World\n";
   return 0;
}

  • Build -> Build Solution wil compile and link your application.
  • Open a Command Window (Start -> Run... and type "cmd")
  • Go to the folder where you have created the project and execute the .exe file that you find there. That is the executable created.
  • Type the name of the .exe file in the Command Window
  • "Hello, World" should appear in the Command Window


-- AlbertoAimar - 30 Aug 2005
Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r4 - 2005-10-21 - JohnHarvey
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    LCGAAWorkbook All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright &© 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
or Ideas, requests, problems regarding TWiki? use Discourse or Send feedback