Makefiles and ROOT. Sean Brisbane 12/12/11



Similar documents
Brent A. Perdue. July 15, 2009

Code Estimation Tools Directions for a Services Engagement

TNM093 Practical Data Visualization and Virtual Reality Laboratory Platform

Building Programs with Make. What does it mean to Build a Program?

GETTING STARTED WITH FLEXI-CLOUD

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

NASA Workflow Tool. User Guide. September 29, 2010

CPSC 226 Lab Nine Fall 2015

Building Software Systems. Multi-module C Programs. Example Multi-module C Program. Example Multi-module C Program

PaperStream Connect. Setup Guide. Version Copyright Fujitsu

Create!form Folder Monitor. Technical Note April 1, 2008

SimbaEngine SDK 9.4. Build a C++ ODBC Driver for SQL-Based Data Sources in 5 Days. Last Revised: October Simba Technologies Inc.

Introduction to ROOT and data analysis

Q N X S O F T W A R E D E V E L O P M E N T P L A T F O R M v Steps to Developing a QNX Program Quickstart Guide

Installing (1.8.7) 9/2/ Installing jgrasp

[PRAKTISCHE ASPEKTE DER INFORMATIK WS 13/14]

Building Software via Shared Knowledge

Programming with the Dev C++ IDE

Tutorial. Reference for more thorough Mininet walkthrough if desired

Code::Block manual. for CS101x course. Department of Computer Science and Engineering Indian Institute of Technology - Bombay Mumbai

CLC Server Command Line Tools USER MANUAL

Xcode Project Management Guide. (Legacy)

Yocto Project Eclipse plug-in and Developer Tools Hands-on Lab

Common SofTest Troubleshooting Techniques

EVALUATION ONLY. WA2088 WebSphere Application Server 8.5 Administration on Windows. Student Labs. Web Age Solutions Inc.

Migrating to Azure SQL Database

Image Acquisition Toolbox Adaptor Kit User's Guide

10 STEPS TO YOUR FIRST QNX PROGRAM. QUICKSTART GUIDE Second Edition

SQL Server Setup for Assistant/Pro applications Compliance Information Systems

Parallels Plesk Control Panel

TIPS & TRICKS JOHN STEVENSON

Zoom Plug-ins for Adobe

Expedite for Windows Software Development Kit Programming Guide

Supported platforms & compilers Required software Where to download the packages Geant4 toolkit installation (release 9.6)

Online Backup Client User Manual

Net Services: File System Monitor

CMake/CTest/CDash OSCON 2009

Insight Video Net. LLC. CMS 2.0. Quick Installation Guide

Blackbaud, Inc. This publication, or any part thereof, may not be reproduced or transmitted in any form or by any means, electronic, or

Easing embedded Linux software development for SBCs

PuTTY/Cygwin Tutorial. By Ben Meister Written for CS 23, Winter 2007

FP File Organizer 3.0 Instruction Manual

Eclipse installation, configuration and operation

PetaLinux SDK User Guide. Application Development Guide

DiskPulse DISK CHANGE MONITOR

InfoView User s Guide. BusinessObjects Enterprise XI Release 2

Extending Remote Desktop for Large Installations. Distributed Package Installs

Creating a Java application using Perfect Developer and the Java Develo...

Creating OpenGL applications that use GLUT

Using SSH Secure Shell Client for FTP

Plesk for Windows Copyright Notice

Hadoop Basics with InfoSphere BigInsights

Universal Management Service 2015

Welcome To Your New Web Hosting Account!

To install Multifront you need to have familiarity with Internet Information Services (IIS), Microsoft.NET Framework and SQL Server 2008.

Virtual CD v10. Network Management Server Manual. H+H Software GmbH

Installing LearningBay Enterprise Part 2

WS_FTP Professional 12

INSTALLATION INSTRUCTIONS FOR THE STUDENT SAMPLE SCHEMA

SDK Code Examples Version 2.4.2

embeo Getting Started and Samples

Customer Database Pro Tutorial

A Crash Course in OS X D. Riley and M. Allen

Code::Blocks Student Manual

Patented hosting technology protected by U.S.Patents 7,0909,948; 7,076,633. Patents pending in the U.S.

CMPT 373 Software Development Methods. Building Software. Nick Sumner Some materials from Shlomi Fish & Kitware

Introduction to ROOT

Source Code Management for Continuous Integration and Deployment. Version 1.0 DO NOT DISTRIBUTE

Kareo Quick Start Guide April 2012

IHS Emergency Department Dashboard

EVault for Data Protection Manager. Course 361 Protecting Linux and UNIX with EVault

CONNECTING TO DEPARTMENT OF COMPUTER SCIENCE SERVERS BOTH FROM ON AND OFF CAMPUS USING TUNNELING, PuTTY, AND VNC Client Utilities

Advanced Bash Scripting. Joshua Malone

Mapping ITS s File Server Folder to Mosaic Windows to Publish a Website

Forms Printer User Guide

BrightStor ARCserve Backup for Linux

ParishSOFT Remote Installation

Utilities ComCash

VERITAS Backup Exec TM 10.0 for Windows Servers

Installation and Deployment

DiskBoss. File & Disk Manager. Version 2.0. Dec Flexense Ltd. info@flexense.com. File Integrity Monitor

Mobile Labs Plugin for IBM Urban Code Deploy

Code Composer Studio Getting Started Guide

Linux command line. An introduction to the Linux command line for genomics. Susan Fairley

Running your first Linux Program

Windows Clients and GoPrint Print Queues

There s a variety of software that can be used, but the approach described here uses freely available Cygwin software: (1) Cygwin/X (2) Cygwin/openssh

CS 103 Lab Linux and Virtual Machines

Setting up FileMaker 10 Server

Contents. Introduction. Chapter 1 Some Hot Tips to Get You Started. Chapter 2 Tips on Working with Strings and Arrays..

SPHOL207: Database Snapshots with SharePoint 2013

Using WinSCP to Transfer Data with Florida SHOTS

Using the enclosed installation diagram, drill three holes in the wall with the lower hole 1150mm from the floor.

Enterprise Service Bus

DigiFlow v1.2: Getting Started with a Site Licence

Integrated Virtual Debugger for Visual Studio Developer s Guide VMware Workstation 8.0

Setting up the Oracle Warehouse Builder Project. Topics. Overview. Purpose

UQconnect + for Life Basics

Freescale Semiconductor, I

Transcription:

Makefiles and ROOT Sean Brisbane 12/12/11

Introduction and purpose By the end of today you should know: The basics of the g++ compiler; How to write Makefiles for medium-sized projects; How to build a program incorporating external libraries i.e. ROOT libraries I assume you have minimal familiarity with the ROOT interpreter and writing ROOT macros. I don t assume any OOP knowledge

Contents ROOT introduction / reminder Compiling, linking and dependencies Automating the build process with Make Your compiled root application TApplication Excercises

Section 1 ROOT INTRO/REMINDER

What is ROOT Interpreted environment CINT Dictionaries Application Libraries

Ways to use ROOT Interpreted environment compiled interpreted Your Code CINT Dictionaries Application Libraries compiled compiled

Running code in ROOT Load macro root [0].L ${ROOTSYS}/tutorials/hsimple.C Compile into shared library: root [0].L ${ROOTSYS}/tutorials/hsimple.C+ Run code: root [1] hsimple() Compile into shared library and run in one go: root [0].x ${ROOTSYS}/tutorials/hsimple.C+ Or from command line: > root ${ROOTSYS}/tutorials/hsimple.C+ Add include path to root (path to additional header files): root [0] groot->processline(".include./include")

Demo (1) Running an interpreted ROOT macro Interpreted environment interpreted Your Code CINT Dictionaries Application Libraries

Demo (2) Compiling within ROOT Interpreted environment compiled Your Code CINT Dictionaries Application Libraries

Section 2 COMPILING, LINKING AND DEPENDENCIES

Source code, objects and Libraries Header files,.h Forward declarations of functions, classes, variables etc. Sould be fairly light, and may be included many times. Is informative, says to the human or the compiler that Something of this name exists with these properties Source code.c,.cpp,.cxx Usually contains the definition of one class or the definition of a few related functions. Implementation of your code. Compilation Code is compiled in separate chunks and stitched together at the end; Object files (.o) usually one source file compiled into machine code. Libraries and linking A collection of one or more objects Static libraries (libmycode.a) can are compiled directly into your executable Large but portable executable, hard to upgrade. Dynamic libraries (libmycode.so) are picked up at load time (or runtime) Linking is performed to allow your program to know which library contains the implementation for each symbol. Small executable, modularity and reusability. Requires the shared libraries to be installed on the systems. A program or executable is basically an object file containing a main function linked to a number of libraries.

Compilation and linking with g++ Object: g++ -I$ROOTSYS/include -fpic -Wall -c hsimple.c -o./hsimple.o -c : Do not link to shared libraries -o : specify the output file -Wall: switch on all compiler warnings -fpic : (position independent code) is required for objects destined for shared libraries -Idir : Add directory dir to the list of directories to be searched include files. Shared Library: g++ -shared hsimple.c -o./libhsimple.so Executable from object: g++ -Wall -L$ROOTSYS/lib mainsimple1.cxx -lcore - lhist -lcint -lrio -ltree -lgpad hsimple.o -o main -Ldir: Add directory dir to the list of directories to be searched for libraries. -l[libname] Link with this library, to be found on the search path(s) specified with -L./main Run Executable

Demo (3c) Compiling outside of ROOT Interpreted environment Your Code CINT Application Dictionaries Libraries compiled In your own time look at demo 3a and 3b, which introduce the gdb debugger

Dependencies There are a lot of interrelated files which go to make up a c++ program. Object files rely on a large number source files (.cpp and.h) Re-build when changes are made When the.o file changes, re-build any files that depend on this Modularity of libraries is important in large programs for build times

Dependency tree (1) Main program made up of three objects, which depend on a header file. Main program Shared Lib 1 Shared Lib 2 Object 1 Object 2 Main program object Source 1 Source 2 Main program source Header file 1 Header file 2 Header file 3

Dependency tree (2) One file changes, only re-build those that require it. Main program Shared Lib 1 Shared Lib 2 Object 1 Object 2 Main program object Source 1 changed Source 2 Main program source Header file 1 Header file 2 Header file 3

Section 3 MAKE

Make Make automates the build process Specify how to build a given file type Resolve file dependencies Rebuild target is source is more recent Not limited to c++ programs Use to automate latex build of thesis Make and Makefiles alone are versatile enough for most mid-sized programs A target can recursively depend on a source file that is itself a target of another rule

First Makefile (1) By default, the make tool looks in the local directory for files named Makefile The core component of Makefiles is the 'rule', which takes the form: target: dependancy #[TAB] line to make target The first target defined in the makefile is the default target It is possible to build other targets by typing : > make -f [makefilename] [targetname] The following rule says that the target main must be rebuilt if depend.o changes. The command below then says how to make it: main : depend.o g++ depend.o -o mainmain4

First Makefile (2) It is possible to use ${} or $() to expand shell environment variables, but in makefiles, they MUST be enclosed in parenthesis of some kind. It is also possible to define variables within the Makefile: MYVAR = foo MYVAR += bar And write a rule in the Makefile to print these : foobar: echo $(MYVAR) $(MYVAR1) Now, on the command line type > make foobar Use := to force make to evaluate the variable immediately, the default is to evaluate it when it is used. The convention is to stick to ${} for shell variables and $() for those defined in the Makefile.

Demo (4a) Automating compilation (Makefiles) Interpreted environment Your Code CINT Application Dictionaries Libraries compiled

Adding local and ROOT shared libraries Creating Shared Libraries: A shared library is created with the shared g++ flag from objects compiled with the fpic flag: libhsimple4.so: hsimple4.o > g++ -shared hsimple4.o -o libhsimple4.so Remember to set your LD_LIBRARY_PATH to the current directory > export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:./ Later, we use the rpath linker command to write the search path into the executable. Adding root Libraries: provides the root-config tool, this helps: Setup include paths > root-config --cflags Setup library paths and a list of commonly used libraries. > root-config -glibs

Adding helper (phony) targets The target all ensures that the rules for each of the end products i.e. the executable and shared libraries are called: all: $(ALLLIBS) $(ALLEXES) The target clean is set to remove all auto-generated files, useful if a re-compile is needed clean: $(RM) $(ALLLIBS) $(ALLEXES) $(ALLOBJS) *.d Add these to a list of.phony special targets, since they do not generate files..phony: all clean

Demo (4b) Shared libraries and phony targets Interpreted environment Your Code CINT Application Dictionaries Libraries compiled

Shortcuts and automatic build rules Make defines a number of helpful shortcuts: $@ : shortcut for the target ; $< : shortcut for the first dependency; $^ : shortcut for all dependencies; % : signifies string substitution. Putting it together into an automatic build rule: %.o: %.cxx $(CXX) $(CXXFLAGS) -c $< -o $@ If a file foo.o is required by another rule, make looks for foo.cxx and runs the command: g++ $(CXXFLAGS) -c foo.cxx -o foo.o

Demo (4c) Automatic rules and rpath Interpreted environment Your Code CINT Application Dictionaries Libraries compiled

Header Dependencies When there is a 1:1 mapping between source files and.o files, the automatic build rules rules work well. Your object files however in general depend on a number of header files. We don t want to pass our header files directly to the build command. Resolution : We specify our header dependencies separately Target : dep1 dep2 Target : dep3 g++ $^ -o target Expands to : g++ dep3 -o target

Advanced topic: Automatic dependency generation Specifying header files like this is duplicating work. We have already written this in our source code in #include header.h statements g++ can generate a list of these for us* and place them into a Separate dependency files (with extension.d ) if we pass g++ the MD flag. We then include these dependency files in our Makefile with the -include directive *You may see other utilities used such as makedepend

Section 4 MISC

Graphics - TApplication So far, our canvases and histograms have not been displayed. However, canvases can still be written to file for later viewing: Can->Print( myhist.eps, eps ) The TApplication ROOT class provides the event loop handling required for graphics. If you want visuals, demo5 gives the boiler plate code in rootapp.cxx and extends this in rootappthreaded.cxx.

Demo (5) Visual feedback Interpreted environment Your Code CINT Application compiled Dictionaries Libraries

Section 4 EXCERCISES

Your working environment Go to the teaching labs on level 2 Log in to Macintosh Notes beside you. Please fill out the tear off slip. Your Mac login is guest[n] Login to pplxint6: ssh pplxint6 l teaching[n] User : teaching[n] Password : teach115btu change your password > yppasswd Start the graphical desktop > startkde When loaded, right click and open a konsole Setup the root environment and check root loads > source /system/sl5/cern/root/x86_64/oxfordsetup-currentpro.sh > root l Quit root root [0].q

Getting the exercises and help The comments in the source code and Makefiles themselves make up the documentation. This is available at: wwwpnp.physics.ox.ac.uk/~brisbane/teaching/makefiles/makefiletutorial.tgz When you are logged in to pplxint6 as a teaching account, open a terminal and: >./getexcercises.sh Further info/material can be found at : Internal www-pnp.physics.ox.ac.uk/~west/intro_manual/node105.html External, basic http://mrbook.org/tutorials/make/ External, advanced http://www.cs.wfu.edu/~burg/courses/fall99/csc112/course-materials/makefileshemler.html

Format Each exercise is self contained. In exercises/ex1a e.t.c. are one or more Makefiles and a README. The README is the place to start Contains overall aims for the exercise and instructions. The Makefile also contains useful instructions and comments Ex0, Ex1a-d are purely on Makefiles Ex 2, 3 &4 include the use of ROOT

ROOT basics ROOT is both a useful interpreter and a collection of reusable libraries Run a tutorial or script: > root ${ROOTSYS}/tutorials/hsimple.C Open a root file and browse it s contents > root hsimple.root root [0] TBrowser cbrowser [Force Re-]Compile a tutorial using roots default compiler (ACLICK): > root ${ROOTSYS}/tutorials/hsimple.C+[+] Documentation: http://root.cern.ch/drupal/content/documentation Where to get ideas and examples: > ls ${ROOTSYS}/tutorials