[boost] [Build] Specify compiler on the command line

1,082 views
Skip to first unread message

Louis Dionne

unread,
Oct 15, 2015, 2:13:50 PM10/15/15
to bo...@lists.boost.org
Hi,

Still attempting to setup Boost.Build for Hana, I find myself unable to
specify the compiler to be used by `b2` on the command line. The system
compiler is then used by default, which does not work because I need to
test on recent compilers.

This can be handled by writing a project-config.jam file with the following
in it:

import feature ;

if ! clang in [ feature.values <toolset> ]
{
using clang : : /path/to/clang ;
}

However, this is not very script-friendly, and I wonder whether there's a way
to specify it on the command-line instead.

Regards,
Louis



_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Andrey Semashev

unread,
Oct 15, 2015, 2:24:29 PM10/15/15
to bo...@lists.boost.org
On 15.10.2015 21:13, Louis Dionne wrote:
> Hi,
>
> Still attempting to setup Boost.Build for Hana, I find myself unable to
> specify the compiler to be used by `b2` on the command line. The system
> compiler is then used by default, which does not work because I need to
> test on recent compilers.
>
> This can be handled by writing a project-config.jam file with the following
> in it:
>
> import feature ;
>
> if ! clang in [ feature.values <toolset> ]
> {
> using clang : : /path/to/clang ;
> }
>
> However, this is not very script-friendly, and I wonder whether there's a way
> to specify it on the command-line instead.

You can use the --toolset option:

bjam --toolset=gcc ...
bjam --toolset=gcc-4.7 ...
bjam --toolset=clang ...

Bjam will look for different versions of compilers installed on the
system and invoke the proper compiler based on the toolset name. You
only have to have lines like these in your user-config.jam:

using gcc ;
using clang ;

Larry Evans

unread,
Oct 16, 2015, 11:07:10 AM10/16/15
to bo...@lists.boost.org
On 10/15/2015 01:24 PM, Andrey Semashev wrote:
> On 15.10.2015 21:13, Louis Dionne wrote:
>> Hi,
>>
>> Still attempting to setup Boost.Build for Hana, I find myself unable to
>> specify the compiler to be used by `b2` on the command line. The system
>> compiler is then used by default, which does not work because I need to
>> test on recent compilers.
[snip]
> You can use the --toolset option:
>
> bjam --toolset=gcc ...
> bjam --toolset=gcc-4.7 ...
> bjam --toolset=clang ...
>
> Bjam will look for different versions of compilers installed on the
> system and invoke the proper compiler based on the toolset name. You
> only have to have lines like these in your user-config.jam:
>
> using gcc ;
> using clang ;
>
>
In case clang is not in normal places,
this part of a user-config.jam would work:

using clang
: 3.7
: "/home/evansl/dwnlds/llvm/3.7/prebuilt/clang+llvm-3.7.0-x86_64-
linux-gnu-ubuntu-14.04/bin/clang++"
: <cxxflags>-std=c++1y
;

an the toolset option would be:

b2 --toolset=clang-3.7

HTH.

-Larry

Louis Dionne

unread,
Oct 16, 2015, 12:49:07 PM10/16/15
to bo...@lists.boost.org
Larry Evans <cppljevans <at> suddenlink.net> writes:

>
> On 10/15/2015 01:24 PM, Andrey Semashev wrote:
> > On 15.10.2015 21:13, Louis Dionne wrote:
> >> Hi,
> >>
> >> Still attempting to setup Boost.Build for Hana, I find myself unable to
> >> specify the compiler to be used by `b2` on the command line. The system
> >> compiler is then used by default, which does not work because I need to
> >> test on recent compilers.
> [snip]
> > You can use the --toolset option:
> >
> > bjam --toolset=gcc ...
> > bjam --toolset=gcc-4.7 ...
> > bjam --toolset=clang ...
> >
> > Bjam will look for different versions of compilers installed on the
> > system and invoke the proper compiler based on the toolset name. You
> > only have to have lines like these in your user-config.jam:
> >
> > using gcc ;
> > using clang ;
> >
> >
> In case clang is not in normal places,
> this part of a user-config.jam would work:
>
> [...]
>
> an the toolset option would be:
>
> b2 --toolset=clang-3.7
>

Yes, this works but the problem is that it's not script friendly, because
you
have to write the file in the right place, and then call b2. I'm trying to
run Boost.Build from Travis, and so far it hasn't been easy. Anyway, I got
it
to work even though it's not pretty.

Thanks,
Louis




--
View this message in context: http://boost.2283326.n4.nabble.com/Build-Specify-compiler-on-the-command-line-tp4680965p4681021.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

Larry Evans

unread,
Oct 16, 2015, 12:50:31 PM10/16/15
to bo...@lists.boost.org
OOPS. For some strange reason, another <cxxflags>
and also a similar <linkflags> is needed to get
the right stdlib in the link:

using clang
: 3.7
:
"/home/evansl/dwnlds/llvm/3.7/prebuilt/clang+llvm-3.7.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang++"
: <cxxflags>-std=c++14
<cxxflags>-stdlib=libc++
<linkflags>-stdlib=libc++
;

Rene Rivera

unread,
Oct 16, 2015, 12:57:42 PM10/16/15
to bo...@lists.boost.org
On Fri, Oct 16, 2015 at 11:37 AM, Louis Dionne <ldio...@gmail.com> wrote:

> Yes, this works but the problem is that it's not script friendly, because
> you
> have to write the file in the right place, and then call b2. I'm trying to
> run Boost.Build from Travis, and so far it hasn't been easy. Anyway, I got
> it
> to work even though it's not pretty.
>

Maybe this helps.. <
https://github.com/boostorg/predef/blob/develop/.travis.yml> The CI support
is experimental so far though.

--
-- Rene Rivera
-- Grafik - Don't Assume Anything
-- Robot Dreams - http://robot-dreams.net
-- rrivera/acm.org (msn) - grafikrobot/aim,yahoo,skype,efnet,gmail

Louis Dionne

unread,
Oct 16, 2015, 10:09:54 PM10/16/15
to bo...@lists.boost.org
Rene Rivera <grafikrobot <at> gmail.com> writes:

>
> On Fri, Oct 16, 2015 at 11:37 AM, Louis Dionne <ldionne.2 <at> gmail.com>
> wrote:
>
> > Yes, this works but the problem is that it's not script friendly, because
> > you
> > have to write the file in the right place, and then call b2. I'm trying to
> > run Boost.Build from Travis, and so far it hasn't been easy. Anyway, I got
> > it
> > to work even though it's not pretty.
> >
>
> Maybe this helps.. <
> https://github.com/boostorg/predef/blob/develop/.travis.yml> The CI support
> is experimental so far though.

AFAICT, you do the same thing I do, i.e. create a dummy Jamroot and a
project-config.jam file containing the toolset configuration. This works,
but I was precisely trying to avoid it since it's not as clean and easy as

cmake .. -DCMAKE_CXX_COMPILER=clang++-3.7

I guess this is the only way to do it with Boost.Build, so it's fine.

Regards,
Louis
Reply all
Reply to author
Forward
0 new messages