Boost logo

Boost-Build :

Subject: Re: [Boost-build] Extending bjam to compile C# source using mono
From: Vladimir Prus (vladimir.prus_at_[hidden])
Date: 2015-09-08 05:05:09

Hi Deane,

On 07-Sep-15 11:55 PM, Deane Yang wrote:
> I am trying to extend Boost Build to compile C# files using csc.exe on
> Windows and msc (Mono compiler) on Linux and OS X.
> First, for backward compatibility reasons, I am using version 1.49.0 of
> boost and building Boost Build v2 using the source provided in that
> distribution.
> The main issues I'm running into are the following:
> 1) How do I set up platform-dependent compiler names and option delimiters
> (/ for windows and - for other OS's)?

You can use the 'path' module for that.

> 2) How do I create a "library" that is called <library name>.dll on all
> platforms rather than, say, lib<library name>.dylib on OS X?

I'll answer this question at the end.

> 3) Most importantly, how do I get the right path to the output of a target?
> When I do the following on OS X:
> feature cs-reference : : free dependency path ;
> flags mcs.make-exe CS_REFERENCE <cs-reference> ;
> actions make-exe
> {
> mcs -target:exe -r:$(CS_REFERENCE) -out:$(<) $(>)
> }
> and my Jamfile has
> lib cslib : cs_source
> ;
> exe test : test.cs
> : <cs-reference>cslib
> ;
> and I do "bjam -n", I get
> mcs -target:exe
> -r:<pbin/darwin-4.2.1/debug/address-model-64/threading-multi>libcslib.dylib
> -out:bin/darwin-4.2.1/debug/address-model-64/threading-multi/test test.cs
> Note the spurious "<p" and ">" in the option "-r:". How do I get rid of
> that?

These characters are parts of the target name, sort of name manging - e.g. 'p' means
this is a target with a specific location on the file system. In order to convert
those into paths inside actions block, you'd use "bind" modifier, e.g.:

        actions make-exe bind CS_REFERENCE

You'd need to also add this code:

        rule link
            DEPENDS $(<) : [ on $(<) return $(CS_REFERENCE) ] ;

This is documented at

Regarding naming of libraries, when you write:

        lib cslib : cs_source ;

you are asking Boost.Build to create a regular library, and therefore the default naming will be used.
In theory it might be possible to adjust the naming based on the types of the sources - i.e. use
custom naming if either one of the sources is .cs, or if all sources are .cs, or similar, but that
might be very brittle, so a better way would be to create new target type. Maybe, assembly-lib,
or similar. Then, you can customized it's suffix easily. You'd need something like:

        import type ;
        type.register ASSEMBLY_LIB : dll : SHARED_LIB ;

this will automatically declare a function 'assembly-lib' that you can use. More details can be found at:

It's generally best to declare generators to support custom tools, which is documented at:

Hope this helps,

Boost-Build list run by bdawes at, david.abrahams at, gregod at, cpdaniel at, john at