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.

#include <iostream>
using namespace std;

int main()
{
  cout << "Hello, World\n";
  return 0;
}

Start emacs and copy the code above:

>emacs hello.cc 

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.

Assuming the above code is in a (source code) file named hello.cc you should be able to compile and execute it with the tools at your disposal. Below is the dialog taken from a command shell when I compiled and executed hello.cc.

>g++ hello.cc -o hello
>./hello
Hello, World
>

Again we just get Hello, World printed on screen. I used the Gnu C++ compiler g++ to do the compilation and ran on a Unix machine for a executable name "hello".

If you cannot compile the above source code or cannot get Hello, World printed on screen then you should stop here and ask for help. There is no way you will be able to get any program running.


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 
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: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r6 - 2005-09-05 - JohnHarvey
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    LCG All webs login

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