h1

How to Install, Build and Use the Boost C++ libraries for development with the Eclipse IDE using the MinGW compiler on a Windows Platform

August 24, 2010

This article outlines how to install, build and use the Boost C++ libraries for development with the Eclipse IDE using the MinGW compiler on a Windows platform.  The article will cover all steps including:

  • Downloading and installing the Eclipse C++ IDE.
  • Downloading and installing the MinGW (GCC, G++, GDB, etc) compiler toolchain.
  • Downloading and installing the Boost library sources.
  • Compiling and running a simple program that uses the Boost header files only.
  • How to build the complete set of Boost binary libraries.
  • How to configure a C++ project in Eclipse IDE to include and link the Boost C++ binary libraries.
  • Finally, we will compile and run a simple program to verify the Boost libraries are correctly installed, built and can be used by your C++ projects.

Overview

We begin by providing a brief overview of the various software components we use in this article.  All of the software components mentioned in this article are free to use for opensource and commercial development.  There are some excellent resources and tutorials included in the references section at the end of this article.  In particular, I have provided references to free online tutorials for C++ programming, and cookbook recipes for C++ and the Boost Libraries.  A cookbook is a collection of hundreds of practical solutions (recipes) to problems that programmers face, with the goal of demonstrating a language’s capabilities and the relative simplicity of implementing them.

What are the Boost C++ libraries?

The Boost C++ Libraries are a collection of free libraries that extend the functionality of C++.  The current Boost release contains over 80 individual libraries (an overview of the libraries are provided here).

Why should a developer/organization use the Boost Libraries?

  • In a word, Productivity. High-quality libraries like Boost speeds initial development, results in fewer bugs, reduces reinvention-of-the-wheel, and cuts long-term maintenance costs.
  • The Boost C++ libraries are open-source and peer-reviewed.
  • The Boost C++ libraries are platform independent and work on almost any modern operating system, including UNIX and Windows variants.
  • The Boost C++ libraries complements the Standard Template Library (STL) rather than replaces it.
  • The Boost C++ libraries are well documented.
  • Most of the Boost libraries are licensed under the Boost Software License, designed to allow Boost to be used with both free and proprietary software projects.

What is the Eclipse C++ IDE?

The Eclipse CDT Project provides a fully functional C and C++ Integrated Development Environment based on the Eclipse platform. Features include: support for project creation and managed build for various toolchains, standard make build, source navigation, various source knowledge tools, such as type hierarchy, call graph, include browser, macro definition browser, code editor with syntax highlighting, folding and hyperlink navigation, source code refactoring and code generation, visual debugging tools, including memory, registers, and disassembly viewers.

What is MinGW?

MinGW, a contraction of “Minimalist GNU for Windows”, is a port of the GNU Compiler Collection (GCC), and GNU Binutils, for use in the development of native Microsoft Windows applications. Offered in easily installed binary package format, for native deployment on MS-Windows, or user-built from source, for cross-hosted use on Unix or GNU/Linux, the suite exploits Microsoft’s standard system DLLs to provide the C-Runtime and Windows API.

1.  Installation of the Eclipse IDE

Download and install the Eclipse for C++ (CDT) IDE.

  1. Ensure you have the Java SE Runtime Environment (JRE) installed.  The Eclipse IDE requires that the Java JRE or JDK be installed in order to run.
  2. Download the Eclipse CDT IDE.  The downloaded file will have a name similar to: eclipse-cpp-helios-win32.zip
  3. Extract the downloaded file to the following folder:  c:\software
  4. Thus, the full path to the eclipse installation should be: c:\software\eclipse
  5. The Eclipse IDE has an extensive inbuilt help menu with detailed user guides and tutorials.

2.  Installation of the MinGW Compiler Toolchain

Download and install the MinGW Compiler toolchain.  Previously, the various components of the GNU toolchain had to be installed individually and manually.  More recently, we can install the entire MinGW toolchain  in one operation from within the Eclipse IDE.

  1. Within the Eclipse IDE, from the menubar, select:  Help | Install New Software.
  2. Enter in the Wascana repository URL (the latest version may be obtained from here) :  
    http://svn.codespot.com/a/eclipselabs.org/wascana/repo
  3. Select the packages that appear and follow the on-screen prompts until the installation is complete.  The package displayed may be: Wascana C/C++ Developer for Windows
  4. The MinGW toolchain will be installed at the following location: c:\software\eclipse\mingwStep 2.1 of this article is illustrated in the following figure:
    MinGW Toolchain Installation (Wascana)
  5. Verify the Eclipse C++ IDE and MinGW toolchain are correct installed and configured by following the simple tutorial from the Eclipse IDE Welcome page.
    1. Within the Eclipse IDE, from the menubar, select: Help | Welcome.
    2. Select: Overview | C/C++ Development | C/C++ Development User Guide | Getting Started | Create a simple Application.
    3. Ensure you can complete the tutorial successfully, before proceeding on (Ensure you can successfully build and run the HelloWorld application).

3.  Installation of the Boost C++ Library Sources

Install the Boost C++ Library sources and header files.  The most important reference for the remainder of this article  is the Boost Getting Started on Windows guide.  You should read the guide in parallel with this article.  However, the guide is written with Visual Studio developers in mind.  In this article, we outline the steps for users of the Eclipse IDE with the MinGW compiler toolchain.  At the time of writing, the current version of the Boost C++ library is 1.44.0.  You should always choose to install the latest version.

  1. Download the latest version of the Boost C++ Libraries.
  2. Extract the zip file to the folder:  c:\software
  3. Thus, the full path to the Boost C++ Library installation folder is:  c:\software\boost_1_44_0

4.  Configure the Eclipse C++ projects to use the Boost C++ Library Headers

All Eclipse C++ projects using the Boost libraries must include the Boost C++ Library installation folder in the include paths.

Using the Getting Started on Windows guide, follow the tutorial Build a Simple Program Using Boost.  The example will use a header-only library.  The simple program reads a sequence of integers from standard input, uses Boost.Lambda to multiply each number by three, and writes them to standard output.

  1. Create a new project as previously illustrated in the HelloWorld Tutorial (suggested new project name is BoostLamdaExample1).
  2. Then create a new source file called example.cpp and cut-and-paste the sample source code from the section Build a Simple Program Using Boost of the guide.
  3. Include the Boost C++ Library installation folder in the include paths of the BoostLamdaExample1 project.
    1. Within the Eclipse IDE, within the project explorer on the left-hand-side, select the C++ project using the Boost libraries.
    2. Right-click over the C++ project and select properties from the context menu.
    3. From within the Properties dialog box, insert the full path of the boost C++ Library installation folder into the following:
      1. C/C++ Build | Settings | GCC C++ Compiler | Includes
      1. C/C++ Build | Settings | GCC G Compiler | Includes
        Step 4.3 of this article is illustrated in the following figure:
        Eclipse IDE Boost Include Path
  4. Build the project BoostLamdaExample1. (Ctrl-B)
  5. Verify the Run Configuration is correct.
    1. From the menubar, select Run | Run Configurations.
    2. Select the BoostLamdaExample1 application.
    3. Verify all the parameters appear correct.
      The Run Configuration is illustrated in the following figure:
      BoostLamdaExample1 Run Configuration
  6. Run the project BoostLamdaExample1.
  7. Enter the input data in the console tab: 1 2 3
  8. Input z to exit the program.
  9. If you are able to run the program successfully, then you have built and run a C++ application using a Boost header library.

5.  Compile and build the Boost C++ Binary Libraries

The Boost C++ Libraries come as source code.  Most of the Boost libraries are header-only libraries.  They consist of header files containing templates and inline functions and do not require separately compiled binary libraries or special treatment when linking.  Although most of the libraries consist solely of header files, there are some important binary libraries required and thus, they must be built.

There are prebuilt binaries of the Boost C++ library for Visual Studio (and only Visual Studio) available for free and may be downloaded from:  BoostPro

We are using the Eclipse C++ IDE with MinGW and so we must compile and build the Boost C++ binary libraries ourselves. We will use BjamBjam is the command-line tool that drives the Boost Build system. To build Boost binaries, we invoke bjam from the Boost C++ Library installation folder.  We will first update two batch files to ensure the build process will proceed smoothly.

  1. Set the toolset to GCC.
    1. Edit the file:  c:\software\boost_1_44_0\bootstrap.bat
    2. Replace the following line:
      set toolset=msvc with the line: set toolset=gcc
    3. Save and exit the file.
  2. Update the build batch file with the correct location of the MinGW toolchain (compiler and linker).
    1. Edit the file: c:\software\boost_1_44_0\tools\jam\src\build.bat
    2. Under the procedure :Guess_toolset, update the MinGW entry to point to the correct folder:
      call :Clear_Error
      if EXIST "C:\software\eclipse\mingw\bin\gcc.exe" (
      set "BOOST_JAM_TOOLSET=mingw"
      set "BOOST_JAM_TOOLSET_ROOT=C:\software\eclipse\mingw\"
      goto :eof)
    3. Optionally, remove all other blocks of code similar to the above codeblock from the procedure :Guess_toolset. This is advisable because you may find that the build procedure quickly exits with the error message saying it cannot find the compiler.  Removing all other codeblocks will ensure the compiler and toolset are set correctly.
      The following figure illustrates the complete :Guess_toolset procedure in my version of build.bat.
      GuessToolkit Procedure
  3. Compile and Build the Boost C++ Library binaries from the command prompt.
    1. Open up a command prompt at:   c:\software\boost_1_44_0
    2. Add the MinGW bin folder to the PATH.
      set PATH=c:\software\eclipse\mingw\bin;%PATH%
    3. Optionally, add python to the end of the PATH.  (Obviously, you may need to download and install it).
      set PATH=%PATH%;c:\python27;
    4. Enter the command:
      booststrap

      This should successfully build the executable Bjam.  If not, please review steps 5.1, 5.2 and 5.3.
    5. Build the Boost Library binaries by issuing the following command (This may take over 2hrs to complete):
      bjam --toolset=gcc  --build-dir=c:\software\boost_1_44_0\build  --build-type=complete  stage

      1. The newly built Boost C++ Binary Libraries are generated in the folder: c:\software\boost_1_44_0\stage\lib
      2. The option: --build-type=complete will generate both debug and release builds of the Boost C++ libraries.  This is suitable for developers.
      3. The option: --build-type=minimal will generate release builds only of the Boost C++ libraries.   This may become an issue for developers who want to create debug builds of their projects.  Since the compiler automatically try to link against the debug builds of the Boost C++ Libraries, an error message is displayed.
      4. The declaration of stage or install specifies whether the Boost C++ Libraries are installed in a subfolder named stage or system-wide. The meaning of system-wide depends on the operating system. In Windows, the target directory is c:\boost,  in Linux it is /usr/local. The target directory can also be explicitly specified using the –prefix option.
      5. The intermediate files are generated in the build folder: c:\software\boost_1_44_0\build You may delete the build folder when the entire build process has completed.
      6. If you have a multi-core processor, you can accelerate the build process.  The option: -j N will run up to n shell commands concurrently. The default is 1.  I have an Extreme Quad-Core processor, and adding the option -j 4 reduced the build time from just over 2hrs to just under 40 minutes.

6.  Configure the Eclipse C++ projects to use the Boost C++ Binary Libraries

  1. All Eclipse C++ project using the Boost C++ binary libraries must include the Boost Binary Library folder in the Libraries (-L) settings.
    1. From with the Eclipse IDE, right-click on the selected project and select Properties.
    2. Place the Boost Binary Library folder path  c:\software\boost_1_44_0\stage\lib in the following location:
      C/C++ Build | Settings | MinGW C++ Linker | Libraries | Library search path (-L).
  2. All Eclipse C++ projects using a specific Boost C++ binary library must include the specific binary library in the Libraries (-l) settings.
    1. From with the Eclipse IDE, right-click on the selected project and select Properties.
    2. Place the name of the specific binary library in the following location:
      C/C++ Build | Settings | MinGW C++ Linker | Libraries | Libraries (-l).
    3. IMPORTANT: To link a Boost C++ Binary library, e.g.: libboost_regex-mgw44-1_44.a the command line option should be: -lboost_regex-mgw44-1_44 (i.e.: Remove the prefix lib and the postfix .a).
  3. Step 6 in this article is illustrated in the following figure:
    Boost Binary Library Folder Configuration

7.  Final step – Verify we can use the Boost C++ Binary Libraries from a sample application.

  1. Using the Getting Started on Windows guide, follow the example Link Your Program to a Boost Library.  To demonstrate linking with a Boost binary library, the sample program extracts the subject lines from emails. It uses the Boost.Regex library, which has a separately-compiled binary component.
  2. Create a new C++ project in Eclipse called BoostRegexExample1 and create a new source file called regex.cpp.
  3. Cut-and-paste the sample code from the section Link Your Program to a Boost Library of the guide into regex.cpp.
  4. Add the Boost installation folder to the Include Path of the BoostRegexExample1 project as indicated in step 4.3 of this article.
  5. Add the Boost Library binary folder to the Library (-L) Path of the BoostRegexExample1 project as indicated in step 6.1 of this article.
  6. Add the specific Boost Regex Binary Library boost_regex-mgw44-1_44 to the library (-l) settings as indicated in step 6.2 of this article.
    1. To find the name of a specific library, please browse the Boost Library binary folder, and select the library filename such that it is the shortest filename with the prefix libboost_regex. The similar looking filenames refer to the same library compiled with different options (statically linked, dynamically link, release-build, debug-build, and so on).
  7. Compile and build (Ctrl-B) the project:  BoostRegexExample1.
  8. Verify the Run Configuration parameters are correct:
    1. From the Eclipse IDE menubar, select Run | Run Configurations.
    2. Ensure the BoostRegexExample1 C++ application is selected.
    3. Ensure the Build configuration is set to Debug.
    4. Click Run.
  9. Cut-and-paste the following sample email into the console as input:
    To: Bob
    From: Mary
    Subject: The test is successful
    Body: Great news, Boost Library integration works.
  10. If the following message is printed out, then the program ran successfully (using the Boost Binary Library Regex).
    The test is successful
  11. To exit the program, input Ctrl-Z to the console.
  12. Congratulations! You may now use the Boost Libraries in your C++ application from the Eclipse CDT IDE using the MinGW toolchain.

References

  • Eclipse C++ IDE – Free fully functional C and C++ Integrated Development Environment.
  • Boost C++ Libraries – Free peer-reviewed portable C++ source libraries.
  • MinGW -  Free port of the GNU Compiler Collection (GCC), and GNU Binutils, for use in the development of native Microsoft Windows applications.
  • Wascana - Wascana is the Eclipse C/C++ IDE for the Windows along with the MinGW GNU toolchain.
  • LearnCpp.com – Free website devoted to teaching you to program in C++.
  • Online C++ Cookbook. – Excellent resource for Java, C++, C#, Oracle and SQL developers.
  • The Boost C++ Libraries Book – An online book providing an overview on using the Boost C++ libraries.  The book is released under a Creative Commons License.
  • cdtdoug.blogspot.com – Personal blog of the Eclipse CDT project  leader providing insights into his mind and the future directions of the project.
h1

How to install the Canon MP610 Printer drivers on 64-bit Ubuntu Lucid Lynx 10.04 (Amd64)

May 3, 2010

This article outlines in simple steps how to install the Canon MP610 printer drivers and get up and running on a 64-bit Ubuntu Lucid Lynx 10.04 platform.

The Canon MP610 is an excellent printer and several previous versions of Ubuntu supported this printer right-out of the box, plug and play style. Unfortunately, the 64-bit Ubuntu Lucid Lynx 10.04 does not have plug and play support for this printer and thus, it does not install by default.  Furthermore, the 64-bit pre-built drivers for this printer are not available. However, the 32-bit pre-built drivers are available.  Lastly, there is also a dependency failure for the libcupsys2 package in the 32-bit version of the driver (the libcupsys2 package has been superseded with the libcup2 package). The situation suddenly appears quite technical and does not look very good.

There are several websites and forums that propose solutions to the above problems.  These solutions vary from compiling the printer drivers from source, to moving around several library files from one folder to another and so on.  Although these solutions work, they are not satisfactory in my eyes because they are prohibitive for all but advanced users of Linux.  A good solution should be as simple as possible but no simpler.

To that end, I will outline below several simple commands that may be run from a terminal (cut-and-paste) which will successfully install the Canon MP610 printer drivers on a 64-bit Ubuntu 10.04 platform. I will then finish this article by outlining how to setup the printer and print a test page.

6 Simple Steps to install the Canon MP610 Printer Driver on 64-bit Ubuntu Lucid Lynx 10.04

  1. Ensure the prerequisite packages are installed. Open up a terminal (From the Ubuntu Desktop Menubar, Select:
    Applications | Accessories | Terminal)
    and run the following command:
    sudo apt-get install ia32-libs cups libcups2 libcups2-dev build-essential
  2. Download the Canon MP610 32-bit printer driver package from the Canon Website.  The driver package is called MP610_debian.tgz (<7MB).  Note: I have linked to the European Canon website, you may obtain the driver from the Canon website appropriate to your location.
  3. Extract the contents of the package MP610_debian.tgz to a folder of your choice.  It should contain the following three files:
    1. cnijfilter-common_2.80-1_i386.deb
    2. cnijfilter-mp610series_2.80-1_i386.deb
    3. cnijfilter-common-2.80-1.tar
  4. Install the cnijfilter-common driver using the following command:
    sudo dpkg -i --force-architecture --ignore-depends=libcupsys2 cnijfilter-common_2.80-1_i386.deb
  5. Install the cnijfilter-mp610 driver using the following command:
    sudo dpkg -i --force-architecture --ignore-depends=libcupsys2 cnijfilter-mp610series_2.80-1_i386.deb
  6. Lastly, restart the CUPS service.
    sudo /etc/init.d/cups restart
  7. Wait a few moments to allow CUPS to restart before continuing on to the next section.

5 Simple Steps to Setup the Canon MP610 Printer and Print a test page.

  1. From the Ubuntu Desktop Menubar, Select:
    System | Administration | Printing
  2. Select Add to add a printer.
  3. Select Canon MP610 when prompted for a device.
    The Installer will attempt to locate a driver for the printer.  This may take a few minutes.
  4. A dialog box containing details of the printer will be presented.  Select:
    Apply
  5. You will then be asked if you wish to print a test page.  Select:
    Yes.

Congratulations!!!  You may now print using the Canon MP610 printer.

h1

How to easily and simply download, install and run the latest Handbrake development snapshot on Ubuntu Lucid Lynx 10.04

April 30, 2010

HandBrakeHandbrake is an excellent open-source, GPL-licensed, multi-platform, multi-threaded video transcoder, available for MacOS X, Linux and Windows.

The latest version of Handbrake  (as at time of writing) is version 0.9.4.   However, some people have experienced problems whereby this version of the application immediately crashes when run on Ubuntu Karmic Kola 9.10 and Ubuntu Lucid Lynx 10.04.  Unfortunately the Handbrake website does not provide pre-built deb packages of older versions (although the source code of older versions is available).

Nonetheless, all is not lost!  The Handbrake community have made it very easy to download, install and run the latest daily development snapshot build of the Handbrake application.  Needless to say, the application code is bleeding edge and may be highly unstable and crash.  That said – it is highly likely the current development is focused on advanced features and it has been my experience thus far that the core functionality works well.

The purpose of this post is to illustrate the steps required to install the latest daily development snapshot of Handbrake.  This post is for advanced users only and be cautioned that the daily snapshots may be highly unstable and may crash your computer system with unpredictable results.  The motivation for this post is simple – It is better to a version of the application providing some of the functionality that a version that doesn’t run at all.

The Steps to Download, Install and Run the latest development snapshot of Handbrake.

  1. Add the daily snapshot source repository location by opening up a terminal and running the following commands.
    sudo add-apt-repository ppa:stebbins/handbrake-snapshots
    sudo apt-get update
  2. From the Desktop Menubar, select:
    System | Administration | Synaptic Package Manager
  3. Select Reload on the ribbon bar immediately under the Synaptic Menubar.
    This will update the package listings in the Synaptic package manager to include the latest snapshot.
  4. In the quick search box on the Synaptic Menubar, enter:
    handbrake
  5. Right-click on handbrake-gtk and select Mark for Installation
  6. On the Synaptic Menubar, select apply and confirm the instructions.
  7. Close the Synaptic Package Manager application.
  8. To run Handbrake:  From the Desktop Menubar, select:
    Applications | Sound & Video | Handbrake

To Disable the Downloading and Installation of newer snapshots.

Please note: each new day the Ubuntu system is updated, the administrator will be prompted to download the latest daily development snapshot of Handbrake.  If the existing snapshot currently installed provides the functionality you require, it is very simple to disable the downloading of  newer snapshots.  The steps are outlined below.

  1. From the Desktop Menubar, select:
    System | Administrator | Software Sources
  2. Select the Other Software Tab.
  3. Uncheck the line containing Handbrake
  4. Close the Software Sources application and choose Reload when prompted.
  5. That’s it!
h1

LaTeX – Getting the Harvard Citation Style to work – Cite URLs properly.

April 1, 2010

The Harvard LaTeX citation package is a requirement for many people when writing research documents or academic theses.

However, the sample LaTeX document harvard.tex that comes with the Harvard citation package available at the CTAN TeX Archive Network does not compile correctly as provided.  This can be somewhat frustrating for many authors, especially those who are quite new to LaTeX.  In attempting to resolve this problem I have developed several solutions which required modifications to the Harvard style file harvard.sty or to the referenced bibliography file harvard.bib. None of these solutions I found to be satisfactory as they are not portable – that is, copying the LaTeX text document to another computer or platform would result is the same problem and require the same fix to be implemented numerous times.

I finally developed a solution that requires modifications to the LaTeX text document only and thus is portable and requires no changes to the underlying latex installation or configuration style files.  I shall begin by outlining the problem as it appears followed by the solution.

Recreating the Problem

  1. Download the Harvard citation package (a zip file) from CTAN.
  2. Extract to a folder of your choice.  E.g.:  C:\temp\harvard
  3. Open up the sample LaTeX document harvard.tex from within your LaTeX editor.  I am using the open source TeXnicCenter IDE.
  4. Attempt to build the document.  You should see an error message similar to the following at the end of your build log.
  5. LaTeX-Result: 19 Error(s), 24 Warning(s), 4 Bad Box(es), 0 Pages.

  6. We are only concerned with eliminating the errors in this post. Normally, the best approach to eliminating errors is to deal with the first error reported as this may be the source of many subsequent errors.
  7. The first error reported is somewhat cryptic:
  8. Paragraph ended before \ltx@LocalAppendToMacro was complete.
    <to be read again>
    \par
    1.6445 }{}

  9. The errors are generated due to several expectations that exist in the harvard.sty file.  However, all of these shall be resolved in the solution specified below.

Implementing the Solution

Ensure you have the sample harvard.tex open in your LaTeX editor.

  1. Insert the following two lines immediately before the line containing \usepackage{harvard}
    \usepackage{html}
    \usepackage{url}
  2. Insert the following line immediately before the line beginning with \title
    \renewcommand{\harvardurl}{URL: \url}
  3. Build your document (at least twice to ensure bibliographic references are resolved) and it should compile without any errors.  Well Done! You may now cite references using the Harvard style in your LaTeX documents.
h1

How to install VNC server on an Ubuntu PC and remote connect to it from a Windows PC

March 16, 2010

Remote DesktopOn the Ubuntu 9.10 PC

The Ubuntu 9.10 PC shall hereafter be referred to as the SERVER.

  1. First of all, permit remote desktop on the SERVER:
    From the menubar, select System | Preferences | Remote Desktop

    1. Under Sharing:
      1. Check  Allow other users to view your desktop
      2. Check  Allow other users to control your desktop
    2. Under Security:
      1. Select  Require the user to enter this password
        and enter a password.
    3. Under Notification area:
      1. Select Only display an icon where there is somebody connected.
    4. Make a note of the network address and name of the SERVER as displayed in the Remote Desktop Preferences.
  2. Now ensure the required applications are installed:
    From the menubar, select System | Administration | Synaptic Package Manager

    1. In the quick search box, type vnc
    2. For each of the following four packages, right-click on them and select Mark for Installation
      1. vnc4server
      2. vnc4-common
      3. vinagre
      4. vino
    3. In the quick search box, type xinetd and install as described above.
    4. Finally, select Apply on the menubar to complete the installation.
  3. Now lets complete the VNC server install and configuration.
    Open up a command terminal:

    1. Run vncpasswd and enter the password that will be required by the client when attempting to connect to the SERVER
      vncpasswd
    2. Run the vncserver on display number 1  in order to generate the configuration files that we will subsequently customize.
      vncserver  :1
    3. If you were to connect via remote desktop from a client at this point, the resolution would be wrong and the screen would be plain grey.  Do not worry, we will fix that now. First, kill the vncserver process by issuing the command:
      vncserver  -kill  :1
    4. Edit the xstartup file in the folder .vnc (make a backup of the file first)
      gedit ~/.vnc/xstartup
    5. Ensure the file has the contents as follows:
    6. #!/bin/sh
      unset SESSION_MANAGER
      sh /etc/X11/xinit/xinitrc

  4. Finally, to run the vnc server on the SERVER (on display 1), issue the command:
    vncserver  :1  -depth 16  -geometry 1028x1024

On the Windows PC

The Windows PC shall hereafter be referred to as the CLIENT.

  1. Download and install the VNC viewer of your cloice.  I am using the free open source UltraVNC viewer.
    Note: UltraVNC is highly customizable.
  2. Run vncviewer.exe
    1. Enter in the network address of the SERVER pc (as recorded in step 1) immediately followed by a colon : and the display number. The following is an example of the format:
    2. 111.222.333.444:1

    3. Under Quick Options, select Auto.
    4. When prompted, enter the password specified in step 3.1
  3. Well Done!  You are now connected over remote desktop to the Ubuntu PC from your Windows PC.

How to configure the VNC server to run at bootup on the Ubuntu PC.

In practice, you will not want to logon to the SERVER just to initiate the VNC server.  Moreover, you may not even have a monitor for your Ubuntu Server, because you may be using the monitor as a dual screen for your primary desktop, as in my case.   :)
These instructions have been referenced from here.

To that end I will now explain how to ensure the VNC server is initialised at bootup time  (simply by switching on the SERVER).  All of the following steps will required you to be logged in as root.

  1. Open up a terminal and login as root
    sudo -i
  2. Run all the commands outlined in step 3 (for the Ubuntu PC) as root.
  3. Create a new file  in /etc/init.d called  vncserver and ensure it has the following contents:
    Note: Change the username (and optionally the other parameters) according to your circumstances.
  4. #!/bin/sh -e
    ### BEGIN INIT INFO
    # Provides:          vncserver
    # Required-Start:    networking
    # Default-Start:     S
    # Default-Stop:      0 6
    ### END INIT INFO
    PATH="$PATH:/usr/X11R6/bin/"
    # The Username:Group that will run VNC
    export USER="YOUR_USERNAME"
    #${RUNAS}
    # The display that VNC will use
    DISPLAY="1"
    # Color depth (between 8 and 32)
    DEPTH="16"
    # The Desktop geometry to use.
    #GEOMETRY="<WIDTH>x<HEIGHT>"
    #GEOMETRY="800x600"
    #GEOMETRY="1024x768"
    GEOMETRY="1280x1024"
    # The name that the VNC Desktop will have.
    NAME="your-vnc-server"
    OPTIONS="-name ${NAME} -depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY}"
    . /lib/lsb/init-functions
    case "$1" in
    start)
    su ${USER} -c "/usr/bin/vncserver ${OPTIONS}"
    ;;
    stop)
    su ${USER} -c "/usr/bin/vncserver -kill :${DISPLAY}"
    ;;
    restart)
    $0 stop
    $0 start
    ;;
    esac
    exit 0

  5. Make the above script executable:
    sudo chmod +x /etc/init.d/vncserver
  6. Make this script into a system service by adding this script to the runtime scripts invoked at bootup time.
    sudo update-rc.d vncserver defaults
  7. To start the service without rebooting the SERVER:
    sudo /etc/init.d/vncserver start
  8. If you made a mistake/typo in the script, you can undo the creation of the system-wide service (step 5) by running the command:
    sudo update-rc.d -f vncserver remove You may then correct your mistake and then repeat steps 5 and 6.
  9. Well done!  You may now connect to your Ubuntu PC SERVER via remote desktop by simply powering on the SERVER and giving it enough time to bootup and run all of its system-wide services.

References

h1

How to Install and Get Up and Running Quickly with GIT – a Fast, Distributed Version Control System.

March 7, 2010

Git LogoI have recently installed and used Git for the first time and I have been impressed by its excellent modular and distributed design, speed, efficiency and usefulness.  So what is Git?

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.  It may be used as a source control management system by software developers.  However, it has a much wider remit and may be used as a version control system for all documents, spreadsheets, presentations and so on.

For some people approaching Git for the first time, it may appear somewhat daunting and overwhelming – not sure where to start, and then how to proceed once on the journey. Thus, the purpose of this article is to provide concise tips and references to facilitate you to get up and running quickly with Git.

Benefits of Version Control

Before jumping into the technical details, I want to briefly outline some of the benefits of a Version Control System (VCS).  They include:

  • Providing snapshots of your documents and the ability to easily go back to an earlier version/revision of your work.
  • Facilitating an efficient and well managed organisation of documents. Experienced document authors compensate for not having a document management system by developing their own naming conventions for each document revision.  As a result, their Documents folder is littered with many revisions of documents using specialized file naming conventions such as file name – date – revision.ext.  A version control system replaces this chaos with a well structured consistent, reliable, efficient and easily managed organisational structure that allows you to focus on the work at hand – the content of your documents.
  • Provides accountability – the ability to maintain and search what was edited when and by whom and what they did.  This is of particular importance when working in a team or collaborating with external members.
  • Adapting to use whatever workflow is appropriate for your project – centralised, distributed, Gatekeeper, and so on.
  • A real time-line of effort put in to complete a project – helps in estimating new projects and billing complete ones.
  • Provision of a backup service (if using a remotely hosted source control solution).
  • Parking projects and then taking them up months/years later and jumping right in by reviewing your comments on what you already did up to the point where you left off.
  • Take risks and make changes knowing that you can always restore a project to a point in time.
  • The ability to create new “branch”  versions. This feature can be useful for making bug fixes when projects have already been released to the field and the next build of the project is in development.
  • Branching also facilitates parallel development. If several people are working on the same project, an integration branch can be created. When any party has new working code, it can be merged to the integration branch where all parties can use the change.
  • Conserving disk space – The VCS only stores the latest version of a file and the differences between each version that precedes it.  Thus the disk space required is usually several orders of magnitudes smaller than what would be required with a VCS.

Install Git and Get up and Running Quickly

  1. If you are new to version control, it is highly recommended you familiarize yourself with the concepts.  An excellent visual introductory guide to version control is available online.
  2. To Install Git on Windows:
    1. There are several different Git installation packages available for installation on Windows.
      I recommend you download and install GitExtensions (which includes MSysGit and KDiff3).  It has the following features:

      • Windows Explorer integration for Git.
      • Visual Studio (2005,2008,2010) plugin for Git.
      • Can be integrated with the Eclipse IDE.
      • Feature rich user interface for Git.
      • Single installer installs Git (MSysGit), GitExtensions, Putty and the merge tool KDiff3.
      • 32bit and 64bit support.
    2. A step-by-step screenshot analysis of each stage of the installation process is available.  In essence, accept the default settings at each stage.
    3. Note: I suggest one change to the default settings:
      When prompted to Adjust your path environment during the Git installation, I recommend selecting:
      Run Git from the Windows Command Prompt

      This will simply allow you to run Git from the command prompt regardless of your current working folder.
  3. To install Git on Ubuntu Linux:
    1. The version installed by apt-get is quite old.  There are simple instructions available to install the latest current stable version here. I recommend installing git-core, git-doc, gitk and git-gui.
  4. To Create a New Repository using the graphical user interface:
    1. Run Git Gui.
    2. Create a new Repository and choose a project folder.
    3. Select everything under Unstaged Changes.
    4. From the MenuBar, Select Commit | Stage to Commit
    5. In the box on the bottom-right of Git Gui, labeled Initial Commit Message, Enter the commit message.
      • The message may include such details as:
        Title_of_Commit
        Name_of_commiter: Joe Bloggs
        Date: 01-01-2000
        Version: 00.01.00
        Description of Changed made:  Several line description.
    6. Select the commit button beside bottom window.
  5. To Create a New Repository using the command line:
    It is even easier to create a new repository from the command line.

    1. Open up a command prompt (windows) or terminal (Linux) and change directory to the project folder. Then enter the following commands:
      1. To create the new repository:
        git init
      2. To add all the contents of the folder into the Git repository:
        git add .
      3. Finally, to commit the files to the repository:
        git commit -m “InitialisedRepository”
  6. To Configure the Eclipse IDE to use Git Gui as an embedded version control management tool:
    There are two excellent and short video tutorials on Youtube to demonstrate this.

    1. Using Git GUI with Eclipse Part I – Setting up the workspace
    2. Using Git GUI with Eclipse Part II – Pushing changes to the server

    Indeed, the method outlined in the videos may be used to integrate Git Gui with any software application that supports external tool configuration and invocation.

Online Resources to help you on your way

  1. Some excellent online resources for learning and using Git:
    • ProGit - An excellent resource for someone new to Git.
  2. Some excellent video screencasts explaining how to use Git:

Git Tips

  1. To configure Git to use an Internet Proxy:
    If your computer passes through a Proxy in order to access the Internet, then Git must be configured to use this Proxy when interacting with repositories on the Internet.  The command to enable Git to use a Proxy is:
    git config –global http.proxy http://our-proxy-server:8088
  2. To configure Git to ignore certain file types:
    Git may be configured to ignore certain filetypes by placing entries in the GIT_DIR/info/exclude file located in the project folder.
    Note: This file must be ready before any files are committed to the Git repository (i.e.: immediately after git init).

    1. The entries may be as follows:
      *.aux
      *.log
      *.blg
      *.[oa]
      filename.ext
    2. For more information, refer to the relevant chapter in the online Git Community Book.
  3. To checkout just one or two files from an older version to be included in the current version:
    Occasionally it may be necessary to check out an old version of just one file and include it in the current working branch (as opposed to checking out the entire older branch just to get that one particular file)  The instructions are in the Git User manual.
  4. To setup your own Git Host Repository:
    There is an excellent guide online explaining step-by-step how to setup a (simple) new remote online repository.
    The steps detailing how to setup a more advanced GIT host repository with automatic user management on a Ubuntu server with clients connecting from Windows are available here.

To access (push, pull and fetch) a GitHub repository from behind a proxy.

The original reference for these instruction are available here.

The typical scenario behind a proxy is:

  • All internet access passes through a proxy.
  • The proxy allows outward connections of type HTTP and HTTPS only (ports 80 and 443 respectively).
  • The CONNECT method is only enabled for port 443.
  • Optionally, proxy authentication is required.

Windows Platform

  1. Install GitExtensions (as described earlier).
  2. Generate your SSH key if you have not already done so and add it to your GitHub account (instructions are available online).  It is also highly recommended you generate a passphrase from reasons outlined here.
    Note: Using Git Gui you may generate your SSH key and  passphrase very easily from the menu bar by selecting Help | Show SSH Key | Generate Key.
  3. Download the utility connect which permits the tunneling of various network connectinos via HTTP(S) proxies.
    The source code connect.c is available for download and compilation.  A pre-compiled binary for windows users is available.
    I placed connect.exe in  C:\software\connect\connect.exe
  4. Backup your existing SSH config file (if it exists).
  5. Create a new SSH config file called config-proxy and place the following text in that file.
    (Note: the text from ProxyCommand to %p should be on one line with a space after “-H”).ProxyCommand C:/software/connect/connect.exe -H proxy.site.com:443 %h %p
    Host github.com
    User git
    Port 22
    Hostname github.com
    IdentityFile “C:\Users\username\.ssh\id.rsa”
    TCPKeepAlive yes
    IdentitiesOnly yes

    Host ssh.github.com
    User git
    Port 443
    Hostname ssh.github.com
    IdentityFile “C:\Users\username\.ssh\id.rsa”
    TCPKeepAlive yes
    IdentitiesOnly yes

  6. Finally, when connecting to your Github repository, specify the remote location as follows (replacing the uppercase words to the appropriate values corresponding to your details):
    ssh://git@ssh.github.com:443/USERNAME/PROJECTNAME.git
    For example, to clone an existing project:
    git clone ssh://git@ssh.github.com:443/USERNAME/PROJECTNAME.git
  7. That’s it!

Google Tech Talks

  • What is Git – A talk by Randal Schwartz.  He presents a good technical overview of Git.
  • Linus Torvalds, the creator of Git, visited Google to share his thoughts on the source control management system. This high-level talk highlights the differences between Git and the alternative version control systems and is quite entertaining as Linus as some strong views on technical matters and design philosophies
h1

How to Install a Full MiKTeX LaTeX Installation and configure TeXnicCenter on Windows XP, Windows Vista and Windows 7

March 7, 2010

TeXnicCenter LogoThe purpose of this article is to outline in concise form the steps required to install and configure a full LaTeX distribution from scratch up to the point of editing documents in LaTeX on a Windows PC.  Furthermore, I will show you how to integrate the LaTeX editor with the PDF viewer to enable you to switch seamlessly between them while creating your documents.

The LaTeX editor employed here is the free open source TeXnicCenter editor which provides all the functionality you need to create, write, build, view and print your LaTeX documents.

Adobe Reader iconPlease ensure you have a PDF viewer already installed before commencing the steps below.  This article will provide instructions on how to configure and integrate two PDF viewers with our LaTeX editor: the free open source PDF viewer Sumatra PDF and the freeware Adobe Acrobat Reader.  You may install either one (or both if you wish).

This article provides instructions for the following platforms: Windows XP, Windows Vista and Windows 7.

  1. Download and run the free open source MiKTeX Net Installer setup-2.X.xxxx.exe from the MiKteX download page. The MiKTeX installation consists of two phases:  the first phase will download the MiKTeX distribution to your PC, the second phase will perform the actual installation.  Once the download operation has finished, the first phase is complete and you are ready to install MiKTeX.  It is recommended to download the latest stable version.  At the time of writing, the latest stable version is 2.9.
  2. To perform the second phase of the installation, start Windows Explorer and browse to the directory which contains the complete MiKTeX distribution (where you downloaded it). Look for a file named setup.exe.   This is the MiKTeX Setup application.  Run setup.exe by double-clicking its icon.  When asked to select a repository folder, select the location of the downloaded MiKTeX distribution. Please be patient as the installation may take quite some time to complete.
  3. Update the MiKTeX Installation:
    From the Start menu, 

    1. On Windows XP:
      select  Start | Programs | MiKTeX 2.X | Update
    2. On Windows Vista or Windows 7:
      select  Start | Programs | MiKTeX 2.X | Maintenance (Admin) | Update (Admin)
    3. Select the option:
      I want to get updated packages from a remote package repository
      and the option:
      Let me choose a remote package repository
      and select the repository nearest you.
    4. Follow the onscreen instructions.
  4. Update the MiKTeX Package Manager:
    From the Start menu, 

    1. On Windows XP:
      select Start | Programs | MiKTeX 2.X | Settings
    2. On Windows Vista or Windows 7:
      select  Start | Programs | MiKTeX 2.X | Maintenance (Admin) | Settings (Admin)
    3. Select the option Refresh FNDB
    4. Select the option Update Formats
    5. Exit the application by clicking Ok.
  5. Install TeXnicCenter:
    1. Download the latest version of TeXnicCenter from
      http://www.texniccenter.org
    2. Run the TeXnicCenter installer and follow the onscreen instructions.
  6. Configure TeXnicCenter’s initial settings:
    1. When running TeXnicCenter for the first time, follow the onscreen instructions.
    2. Close and rerun TeXnicCenter.
    3. Select Tools | Options | Editor Tab
      Enable display line numbers
  7. If you are running Windows Vista or Windows 7:
    1. Configure the TeXnicCenter application to run as an administrator.
    2. Configure the TeXnicCenter application to run in compatibility mode: Windows XP SP3.
    3. If you will use Sumatra PDF as your PDF viewer, configure the Sumatra PDF application to run in compatibility mode: Windows XP SP3.
  8. A brief explanation of terminology concerning Integration features between TeXnicCenter and the PDF viewers is now required.
    Several PDF viewers support the concept of Forward-Search and Inverse-Search. 

    • What is Forward-Search?: When compiling (generating PDF output) your LaTeX source document in TeXnicCenter, Forward-Search enables the current editing location in the source latex file to be displayed and highlighted in the generated PDF.  For example, if you are editing text that appears on page 8 of the PDF; after compiling the LaTeX source, the PDF viewer will open the document and jump directly to page 8 to display the text you have just edited.  This is a great timesaver.  The communication between the editor and PDF viewer often relies on the DDE protocol.
    • What is Inverse-Search?: Inverse-Search is a synchronisation feature whereby doubling-clicking on a line in the PDF document will switch to the LaTeX editor and display the corresponding line in the document source.  Again, another great timesaver.
    • Adobe Reader and Adobe Acrobat:
      Forward-Search and Inverse-Search may not work with adobe Reader version 8 or higher (i.e.: all recent versions).
    • Sumatra PDF Viewer:
      Forward-Search and Inverse-Search function correctly using Sumatra PDF on Windows XP SP3, Windows Vista and Windows 7. This author’s preference is to use the Sumatra PDF viewer to view the document during the creation and editing phases, and only use Adobe Reader to view the final completed document to verify the final document version appears correctly when viewed with Adobe Reader.
      Note 1: At present (TeXnicCenter v1.0 and Sumatra V1.3), forward search only works if the file name and entire file path do not contain spaces!

      Note 2: Be aware that cutting and pasting the configuration information that appears in the subsequent steps from this webpage directly into the TeXnicCenter configuration panel may not work.  The double-quotes (and single-quotes) are often misrepresented.
  9. To configure TeXnicCenter to view document output using Adobe Reader:
    1. Run TeXnicCenter.
    2. Select Build | Define Output Profiles | Viewer Tab
    3. Ensure the profile selected is LaTeX => PDF
      For both View Project’s Output and Forward Search options, enter the following: 

      1. Enable DDE
      2. Command: [DocOpen("%bm.pdf")][FileOpen("%bm.pdf")]
      3. Server: acroview
      4. Topic: control
    4. For Close Document before running LaTeX:
      1. Enable DDE
      2. Command: [DocClose("%bm.pdf")]
      3. Server: acroview
      4. Topic: control
  10. To configure TeXnicCenter to view document output using Sumatra PDF:
    The Sumatra PDF viewer integrates nicely with TeXnicCenter supporting both forward-search and inverse-search. 

    1. Run TeXnicCenter.
    2. Select Build | Define Output Profiles | (La)Tex Tab
      1. Select Add to add a new profile.
        Enter the profile name:  Latex => PDF (Sumatra)
    3. Under the (La)TeX Tab
      1. Select the checkbox:  Run (La)TeX compiler
        1. Path to the latex compiler:
          C:\software\MiKTeX 2.8\miktex\bin\pdflatex.exe
          Note: The path references may be different on your computer.
        2. Command line arguments to pass to the compiler:
          -interaction=nonstopmode “%pm” -synctex=-1
      2. Unselect the checkbox:  Do not use BibTeX in this profile
         

        1. Path to BibTeX executable:
          C:\software\MiKTeX 2.8\miktex\bin\bibtex.exe
        2. Command lne arguments to pass to BibTeX:
          “%bm”
      3. Unselect the checkbox:  MakeIndex
        1. Path to MakeIndex executable:
          C:\software\MiKTeX 2.8\miktex
          \bin\makeindex.exe
          Note: The path should be on one line, I split the path here to ensure it displays clearly. There should be no space  at the line break between miktex and \bin.
        2. Command line arguments to pass to MakeIndex:
          “%bm”
    4. The Postprocessor tab may be left blank.
    5. Under the Viewer Tab:
      1. Path to executable:
        C:\software\SumatraPDF\SumatraPDF.exe
        -inverse-search “\”C:\software\TeXnicCenter\TEXCNTR.EXE\”
        /ddecmd \”[goto('%f','%l')]\”"
        Note: The path should be on one line, I split the path here to ensure it displays clearly.  There should be a space inserted at the position of the line breaks:
         

        • one space after SumatraPDF.EXE
        • another space after TEXCNTR.EXE\
      2. For View project’s output:
        1. Enable Command line argument
        2. Command: “%bm.pdf”
      3. For Forward Search:
         

        1. Enable DDE command:
        2. Command: [ForwardSearch("%bm.pdf","%Wc",%l,0)]
        3. Server: sumatra
        4. Topic: control
      4. For Close document before running (La)Tex
        1. Enable Do not close.
  11. Well Done!  You are now ready to create beautifully typesetted PDF documents.  Enjoy!

References

Follow

Get every new post delivered to your Inbox.