C++ basic for Build and Release Engineers

The compiler
Compiler is the software that translates the syntactically correct statements of a program into objectcode or can also produce an executable using a linker and the object code produced. An object codecan’t be run directly on a machine since it contains information about the object module in addition tothe machine instructions.

The linker
A linker is another program which is invoked upon compiled object files. A linker just identifies thestructure of the object files, resolves the functions and object linkages and creates an executable

To understand linkers, it helps to first understand what happens “under the hood” when you convert a source file (such as a C or C++ file) into an executable file (a file that can be executed on your machine or someone else’s machine running the same architecture).

Under the hood, when a program is compiled, the compiler converts the source file into object byte code. This byte code (sometimes called object code) is mnemonic instructions that only your computer architecture understands. Traditionally, these files have an .OBJ extension.

After the object file is created, the linker comes into play. More often then not, a real program that does anything useful will need to reference other files. In C, for example, a simple program to print your name to the screen would consist of:
printf(“Hello Nick!\n”);

When the compiler compiled your program into an obj file, it simply put a reference to the printf function. The linker resolves this reference. Most programming languages have a standard library of routines to cover the basic stuff expected from that language. The linker links your OBJ file with this standard library. The linker can also link your OBJ file with other OBJ files. You can create other OBJ files that have functions that can be called by another OBJ file. The linker works, almost like a word processor’s copy and paste. It “copies” out all the necessary functions your program references and creates a single executable. Sometimes other libraries that are copied out are dependent on yet other OBJ or library files. Sometimes a linker has to get pretty recursive to do its job.

Note that not all operating systems create a single executable. Windows, for example, uses DLL’s that keep all these functions together in a single file. This reduces the size of your executable, but makes your executable dependant on these specific DLLs. DOS used to use things called Overlays (.OVL files). This had many purposes, but one was to keep commonly used functions together in 1 file (another purpose it served, in case you’re wondering, was to be able to fit large programs into memory. DOS has a limitation in memory and overlays could be “unloaded” from memory and other overlays could be “loaded” on top of that memory, hence the name, “overlays”). Linux has shared libraries, which is basically the same idea as DLL’s (hard core linux guys I know would tell me there are MANY BIG differences).

The procedure for compiling a C++ program is the same as for a C program, but uses the command g++ instead of gcc. Both compilers are part of the GNU Compiler Collection.

Sample C++ Program 1
======================

#include <iostream>
int main()
{
using namespace std;
cout << “Hello world!” << endl;
return 0;
}

The program can be compiled with the following command line:
g++ -Wall hello.cc -o hello

The resulting executable can be run in exactly same way as the C version, simply by typing its filename:
$ ./hello Hello, world!

Sample C++ Program 2
======================

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
int x = 0;
while(x < 10) {
double y = sqrt((double)x);
cout << “The square root of ” << x << ” is ” << y << endl;
x++;
}
return 0;
}

Building on the Command Line

CL
Use the compiler (cl.exe) to compile and link source code files.

The compilers produce Common Object File Format (COFF) object (.obj) files. The linker produces executable (.exe) files or dynamic-link libraries (DLLs).

Link
Use the linker (link.exe) to link compiled object files.

MSBuild (Visual C++)
Use MSBuild to build Visual C++ projects and Visual Studio solutions from the command line. Invoking this utility is equivalent to running the Build project or Build Solution command in the Visual Studio integrated development environment.

The build process is controlled by the information in a project file (.vcxproj) that you can create and edit. The project file specifies build options based on build stages, conditions, and events.

DEVENV
Use DEVENV combined with a command line switch, such as /Build or /Clean, to perform certain build commands without displaying the Visual Studio IDE.

Devenv lets you set various options for the integrated development environment (IDE), and also build, debug, and deploy projects, from the command line. Use these switches to run the IDE from a script or a .bat file, for example, a nightly build script, or to start the IDE in a particular configuration.
For example, the command devenv /build myproject1.vbproj

NMake
Use NMake to automate tasks that build Visual C++ projects. The Microsoft Program Maintenance Utility (NMAKE.EXE) is a tool that builds projects based on commands contained in a description file.

Reference
http://msdn.microsoft.com/en-us/library/f35ctcxw.aspx

Header file vs Library

Generally, a header file notifies the compiler of certain things (mostly their existence or declarations) so that the compiler can correctly build a single translation unit (such as a single C file).

A library file is the actual executable code that does the work as specified in that header file. This is linked in by the linker to provide the actual functionality (the _definitions rather than just the declarations).

Header Files: These are the files that are included at the top of any program. If we use any function inside a program, then the header file containing declaration or definition of that function ,has to be included.Like printf() is defined in stdio.h.So, we must include it (by #include in order to use printf().

Library Files: These are the files which the compiler uses in order to define the functions which have been used in the program and had been declared inside the header file.Like, printf() has its complete definition ,like how it will work etc. in an I/O library! So, the compiler uses that library to get the machine code for printf.

Difference:
Header files are TEXT files while library files are BINARY. This means, we can read and modify the header file but not the library!
Header file is in C language while the library is in machine language!
Header file has to be included by the programmer while the compiler automatically relates the library file(s) with the program!

Tagged : / / / / / / / /

Introduction of MSbuild

Hi Guys,

can u pl help me anyone Introduction of MSbuild?

Regards,

Rambabu.M

  • Rajesh Kumar

    Rajesh Kumar 

    MSBuild Overview

    The Microsoft Build Engine (MSBuild) is the new build platform for Microsoft and Visual Studio. MSBuild is completely transparent with regards to how it processes and builds software, enabling developers to orchestrate and build products in build lab environments where Visual Studio is not installed. This topic provides brief overviews of:

    • The basic elements of an MSBuild project file.
    • How MSBuild is used to build projects.
    • The advanced features of MSBuild.
    • How Visual Studio uses MSBuild to build projects.

    Project File


    MSBuild introduces a new XML-based project file format that is simple to understand, easy to extend, and fully supported by Microsoft. The MSBuild project file format enables developers to fully describe what items need to be built as well as how they need to be built with different platforms and configurations. In addition, the project file format enables developers to author re-usable build rules that can be factored into separate files so that builds can be performed consistently across different projects within their product. The following sections describe some of the basic elements of the MSBuild project file format.

    Items

    Items represent inputs into the build system and are grouped into item collections based on their user-defined collection names. These item collections can be used as parameters for tasks, which use the individual items contained in the collection to perform the steps of the build process.

    Items are declared in the project file by creating an element with the name of the item collection as a child of an ItemGroupelement. For example, the following code creates an item collection named Compile, which includes two files.

    <ItemGroup>
        <Compile Include = "file1.cs"/>
        <Compile Include = "file2.cs"/>
    </ItemGroup>
    
    

    You reference item collections throughout the project file with the syntax @(ItemCollectionName). For example, you reference the item collection in the example above with @(Compile).

    Items can be declared using wildcards and may contain additional metadata for more advanced build scenarios. For more information on items, see MSBuild Items.

    Properties

    Properties represent key/value pairs that can be used to configure builds. Items and properties differ in the following ways:

    • Items are stored in collections, while properties contain a single scalar value.
    • Items cannot be removed from item collections, while properties can have their values changed after they are defined.
    • Items can contain metadata and can use the %(ItemMetadata) notation, while properties cannot.

    Properties are declared by creating an element with the name of the property as a child of a PropertyGroup element. For example, the following code creates a property named BuildDir with a value of Build.

    <PropertyGroup>
        <BuildDir>Build</BuildDir>
    </PropertyGroup>
    
    

    You reference properties throughout the project file with the syntax $(PropertyName). For example, you reference the property in the example above with $(BuildDir). For more information on properties, see MSBuild Properties.

    Tasks

    Tasks are reusable units of executable code used by MSBuild projects to perform build operations. For example, a task might compile input files or run an external tool. Once created, tasks can be shared and reused by different developers in different projects.

    The execution logic of a task is written in managed code and mapped to MSBuild with the UsingTask element. You can write your own task by authoring a managed type that implements the ITask interface. For more information on writing tasks, see How to: Write a Task.

    MSBuild ships with many common tasks such as Copy, which copies files, MakeDir, which creates directories, and Csc, which compiles Visual C# source code files. For a complete list of available tasks and usage information, see MSBuild Task Reference.

    You execute a task in an MSBuild project file by creating an element with the name of the task as a child of a Targetelement. Tasks usually accept parameters, which are passed as attributes of the element. MSBuild item collections and properties can be used as parameters. For example, the following code calls the MakeDir task and passes it the value of the BuildDir property declared in the previous example.

    <Target Name="MakeBuildDirectory">
        <MakeDir
            Directories="$(BuildDir)" />
    </Target>
    
    

    For more information on tasks, see MSBuild Tasks.

    Targets

    Targets group tasks together in a particular order and expose sections of the project file as entry points into the build process. Targets are often grouped into logical sections to allow for expansion and increase readability. Breaking the build steps into many targets allows you to call one piece of the build process from other targets without having to copy that section of code into each target. For example, if several entry points into the build process require references to be built, you can create a target that builds references and run that target from every necessary entry point.

    Targets are declared in the project file with the Target element. For example, the following code creates a target named Compile, which then calls the Csc task with the item collection declared in the previous example.

    <Target Name="Compile">
        <Csc Sources="@(Compile)" />
    </Target>
    
    

    In more advanced scenarios targets can describe relationships between each other and perform dependency analysis, which allows whole sections of the build process to be skipped if that target is up-to-date. For more information on targets, see MSBuild Targets.

    Building with MSBuild


    You run MSBuild from the command line by passing a project file to MSBuild.exe with the appropriate command line options. Command line options allow you to set properties, execute specific targets, and specify loggers. For example, you would use the following command line syntax to build the file MyProj.proj with the Configuration property set to Debug.

    MSBuild.exe MyProj.proj /property:Configuration=Debug
    
    

    For more information on MSBuild command line options, see MSBuild Command Line Reference.

    Security noteSecurity Note:
    Before you build a downloaded project, determine the trustworthiness of the code. MSBuild project files have the ability to execute tasks that can damage your system.

    Advanced concepts


    MSBuild can be used for more advanced operations during builds, such as logging errors, warnings, and messages to the console or other loggers, performing dependency analysis on targets, and batching tasks and targets on item metadata. For more information on these advanced concepts, see MSBuild Advanced Concepts.

    Visual Studio Integration


    Visual Studio uses the MSBuild project file format to store build information about managed projects. Project settings added and changed through Visual Studio are reflected in the .*proj file that is generated for each project. Visual Studio uses a hosted instance of MSBuild to build managed projects, meaning that a managed project can be built in Visual Studio and from the command line (even without Visual Studio installed), with identical results. For more information on how Visual Studio uses MSBuild, see MSBuild Advanced Concepts.

    Source:

    http://msdn.microsoft.com/en-us/library/ms171452%28VS.90%29.aspx

     

  • Rambabu Muppuri

    Rambabu Muppuri 

    hi raj , thanks for ur comments ..could u pl let me know how can we increment version numbers through msbuild tool..i have written below xml tag but which is not working ..pl help me..
    <Target Name=”Version”>if its possible send one exmaple with version numbers increment..

    <Message Text=”Version: $(Major).$(Minor).$(Build).$(Revision)”/>

    <AssemblyInfo CodeLanguage=”VB”

    OutputFile=”My Project\AssemblyInfo.vb”

    AssemblyTitle=””

    AssemblyDescription=””

    AssemblyCompany=””

    AssemblyProduct=””

    AssemblyCopyright=””

    ComVisible=”false”

    CLSCompliant=”true”

    Guid=”d038566a-1937-478a-b5c5-b79c4afb253d”

    AssemblyVersion=”$(Major).$(Minor).$(Build).$(Revision)”

    AssemblyFileVersion=”$(Major).$(Minor).$(Build).$(Revision)”

    Condition=”$(Revision) != ‘0’ “/>
    </Target>

  • Rajesh Kumar

    Rajesh Kumar 

    Long time back same thing i did using Apache ant, you can find logic here http://www.scmgalaxy.com/component/content/article/62-apache-ant/129-ant-script-to-reset-buildnumber.html

     

    meanwhile, I will try to create using MSBuild in free time.

Tagged : / / / /

XML Is the Here, the Now, and the Future

XML Is the Here, the Now, and the Future

XML is short for Extensible Markup Language, which is a specification developed by the World Wide Web Consortium (W3C). XML is a pared-down version of SGML, designed especially for Web documents. It allows designers to create their own customized tags, enabling the definition, transmission, validation, and interpretation of data between applications and between organizations.

Following are three good reasons why you should master XML:

  • XML is seen as a universal, open, readable representation for software integration and data exchange. IBM, Microsoft, Oracle, and Sun have built XML into database authoring.
  • .NET and J2EE (Java 2 Platform, Enterprise Edition) depend heavily on XML.
    • All ASP.NET configuration files are based on XML.
    • XML provides serialization or deserialization, sending objects across a network in an understandable format.
    • XML offers SOAP Web Services communication.
    • XML offers temporary data storage.
  • MSBuild and the future project files of Visual Studio will be in XML format. ANT is also XML based.

Thus, if you want to learn one language that will cover many tools and technologies no matter what platform you are working on, that language is XML. The main difference in all these build tools is not so much the feature set but the syntax. I get tired of learning all the quirks of new languages, but I’m happy to learn XML because it’s here to stay and it’s fairly easy to learn.

Tagged : / / / / /

Msbuild slower than devenv

scmuser created the topic: msbuild slower than devenv
Hi, I’m experiencing performance inconsistencies with regards to build duration when building a VS2008 solution file with either devenv or msbuild from command line.

My solution contains both C# and C++ projects, and I have these results:

devenv.exe (either command line or within the ide): 7 minutes msbuild.exe: 14 minutes

I tried tuning the msbuild switches passing /maxcpucount and /p:VCBuildAdditionalOptions=m# but with no luck so far.

Any idea?

scmuser replied the topic: Re:msbuild slower than devenv
what is the full msbuild command you are running?

As a side point, have you got the build output turned down to Quiet or Minimal? That reduces build time a little…

7 minutes to build in the IDE!! Personally I’d go insane, debugging must be a nightmare

Tagged :

MSBuild Tool

rambabu1683 created the topic: MSBuild Tool
Hi guys,

i am new to this forum.
can anyone help me about MSBUILD tool with small examples?

Warm Regards,
Rambabu.M

rajeshkumar replied the topic: MSBuild Tool
These quicks urls might help you…
www.scmgalaxy.com/189-msbuild/229-introduction-to-msbuild.html
www.scmgalaxy.com/189-msbuild/161-runnin…ous-integration.html
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :

Good Links for Continuous integration with Team City and MSBuild

rajeshkumar created the topic: Good Links for Continuous integration with Team City and MSBuild
Continuous integration with Team City and MSBuild

bjarte.com/post/continuous-integration-with-team-city-and-msb
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :

Help with MSbuild 4 and custom tasks

rajeshkumar created the topic: Help with MSbuild 4 and custom tasks
I’m trying to build a custom task using the Task base class in Microsoft.Build.Utilitieis.v4.0. I have the task built and compiled just fine but I get this error

C:\sandbox\c-wundram\msbuild\TalTrade.Importer\TestImporterTask\TestImporterTas
k.csproj(58,5): error MSB4062: The “Importer” task could not be loaded from the
assembly C:\sandbox\c-wundram\msbuild\TalTrade.Importer\TalTrade.Importer\bin\
debug\TalTrade.Importer.dll. Confirm that the declaration is corre
ct, that the assembly and all its dependencies are available, and that the task
contains a public class that implements Microsoft.Build.Framework.ITask.

However the path is correct, and the class which subclasses Task is public. I tried checking the binding using fuslogvw, and it doesn’t appear to even attempt to load my assembly. Does anyone have any ideas of what might be going wrong? The only depenendencies my assembly has is on the framework, and on the TFS 2010 APIs.
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

boris replied the topic: Re:Help with MSbuild 4 and custom tasks
Hiho,

As far as I understand, you are *not* talking about Rational BuildForge (or there may be several buildforge names).

If you want to get some answers, you should repost in a more appropriate forum (e.g. MS Build).

Cheers,


boris

Tagged :

MSBuild feature

geethusri26 created the topic: MSBuild feature
Hi,

Can anyone share TFS MSbuild features in ppt or slideshow ?

rajeshkumar replied the topic: Re:MSBuild feature
Hi,

please check here…

scmgalaxy.com/index.php?option=com_conte…ry&id=195&Itemid=186

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

geethusri26 replied the topic: Re:MSBuild feature
Hi Rajesh,

Thanks for the link.

Do you have any presentation for TFS build alone?

If you have any notes for that can you please share it ?

Thanks,
Geetha

rajeshkumar replied the topic: Re:MSBuild feature
Hi Questions is not clear.

you would to like know about TFS or TFS association with build server?

Which build tool you are using? Can you provide more details of this?
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

ajay.katke@gmail.com replied the topic: Re:MSBuild feature
Even I am in need of TFS admin PPT or document !!

@ Rajesh
Can you help me in this ?!

Thanks,
Haresh

rajeshkumar replied the topic: Re:MSBuild feature
Hi Krish,

this may help you….

tinyurl.com/397fagj

Else best would be referring Help Menu. I guess you will have tutorials as part of software installation(TFS)…

Happy New Year 2010
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :

Top 5 Build Management Tools

top-5-build-management-tools
These days in software industry the process of software development very much rely upon best practices of various tools. The software development teams use various tools like project management, release management , test management and various others. As we already discussed about these tools in our previous posts. But, today we are going to discuss about Build management tool. This is one of the most important tool which required in any kind of software development. In this article we are going to discuss about Top Build Management Tools.
But before that let’s have a quick overview on Build management.
Build management is actually a process of collecting all the components in a software release, performing all the automated tasks to compile, build and test the system and then deploy onto the development and testing environments in preparation for staging. It has become an important part of software development in testing process.
But you can not simply do build management without tools. it is also important to ensure that tools are selected properly and thoroughly so that each of them provides the desired service.
So, without wasting any time let’s have a look on top 5 build management tools
1. Apache Maven
 Apache Maven
Maven is an open source build management tool which is distributed under Apache License. It is basically used for Java projects. let’s have a look on key feature of Maven tool
Key Features
  • Open source
  • Based on Project Object Model or POM
  • Release management and distribution publication
  • Coherent site of project information
  • Instant access to new features
  • Extensible with plugins
  • Works easily with multiple projects simultaneously
  • Simple project setup

2. Gradle

 

 Gradle

Gradle is also an open source build management tool which is distributed under Apache License. It is written in java and groovy supports cross platform. Let’s have a look on key features

Key Features
  • Open source
  • Designed for multiple projects
  • Supports incremental builds
  • Rich API
  • Mature ecosystem of plugins
  • Ease of migration
  • First build integration tool
  • Declarative builds and build-by-convention

3. Apache Ant

 

Apache Ant
Apache Ant is also an open source build automation tool which is distributed under Apache License. It is also a Java based build tool. Let’s have a look on key features
Key Features
  • open source
  • Ease of Use
  • Independent Platform
  • Can execute test scripts and test suites
  • Can copy files to at different locations
  • Supports Junit 3, Junit 4, Testing etc.
  • Able to compile java based applications
  • Can check out the code from version control system (SVN, GIT, CVS etc).
4. MSBuild
 MSBuild
MsBuild or Microsoft build tools as its name indicates it belongs to Microsoft which is written in C# and supports .Net framework and available under MIT license.
Key features
  • Able to build Visual Studio projects without Visual Studio IDE installed
  • Now bundled with Visual Studio
  • Multitargeting
  • Description language – XML
5. FinalBuilder
 FinalBuilder
Finalbuilder is a build tool which supports Windows platform and it is developed by VSoft Technologies in the year 2000. It is available under Proprietary license.
Key Features
  • It can present your build process in a structured manner
  • With FinalBuilder you don’t need to edit xml, or  write scripts
  • Allows builds to be scheduled to run daily, weekly or whenever you wish
  • Extensive library of pre-written actions to automate every common task in build process
  • Integrated Debugging
  • Detailed Logging
  • Version Control Integration
Do you agree with this list? If not than feel free to respond in the comment box with your own take on the top build management tools. One more thing, I would like to add here, if you need help to learn all these build tools or DevOps courses than scmGalaxy can help you in this. scmGalaxy is a community of DevOps professionals who are well experienced in this domain. So, feel free to reach us.
Tagged : / / / / / / / / / / / / /

MSBuild Tutorial Reference for Beginner | MSBuild Learning Resources | scmGalaxy

msbuild-tutorial

Walkthrough: Creating an MSBuild Project File from Scratch

How to: Write a Simple MSBuild Project

MSBuild Basics

Build Your Project File from Scratch using MSBuild

Tagged : / / / / / / / / / / / /