my experience with Meson and a couple of questions

307 views
Skip to first unread message

Francesco Abbate

unread,
Aug 21, 2017, 5:11:29 AM8/21/17
to The Meson Build System
Hi,

I'm starting using Meson to build one of my C/C++ project on Windows using MinGW and on Linux.

So far my experience with Meson is really good. I was able to get rid of a lot of complexity related to the Makefile builds. In comparison the simplicity of Meson is really refreshing. On the other side I lost a little bit of fine-grained control about how exactly things should be compiled and linked but that's ok for me.

So I have two questions to re-gain some of the lost control :-)

1. for the 'debug' build only I would like to enable a specific compiler define ('-DDEBUG'). For the moment I found no solution except to define a 'debug' option. Than when I'm doing a release build I manually set the debug option to false. Is it possible to instruct Meson to enable the compiler flag '-DDEBUG' only for debug build ? More generally I found no options to inquire in the meson.build the 'buildtype'.

2. Meson link c++ application using 'g++' and the executable is linked to libstdc++. My application does not use the C++ standard library so I don't want to link to libstdc++. The standard way to achieve that is to link the executable using 'gcc' instead of 'g++' and add '-lsupc++'. How I can achieve that with Meson ? If possible I would prefer to avoid using environment variables but have these options inside the 'meson.build'.

Thank in advance for any help and a big thanks Jussi and all the contributors of the project for creating Meson and make it free software, you have made an amazing work.

Kind regards
Francesco

Jussi Pakkanen

unread,
Aug 21, 2017, 5:24:56 AM8/21/17
to Francesco Abbate, The Meson Build System
On Mon, Aug 21, 2017 at 12:11 PM, Francesco Abbate
<france...@gmail.com> wrote:

> flag '-DDEBUG' only for debug build ? More generally I found no options to
> inquire in the meson.build the 'buildtype'.

get_option('buildtype')

> 2. Meson link c++ application using 'g++' and the executable is linked to
> libstdc++. My application does not use the C++ standard library so I don't
> want to link to libstdc++. The standard way to achieve that is to link the
> executable using 'gcc' instead of 'g++' and add '-lsupc++'. How I can
> achieve that with Meson ? If possible I would prefer to avoid using
> environment variables but have these options inside the 'meson.build'.

Meson builds with -Wl,--as-needed by default so if you are not using
anything from stdlibc++ the linker should remove it from the list of
dependencies. Gcc does have command line options like -nostdlib or
-nostdinc which could do what you want but I have never used them
myself for this so you'll need to try them out yourself.

But perhaps the biggest question is does the extra library really
matter? If you don't have a really good reason (such as something
breaking if you link with stdlibc++) then maybe it is simpler to just
let it do the default thing and not worry about it.

Francesco Abbate

unread,
Aug 21, 2017, 4:31:13 PM8/21/17
to The Meson Build System, france...@gmail.com
Le lundi 21 août 2017 11:24:56 UTC+2, Jussi Pakkanen a écrit :
Meson builds with -Wl,--as-needed by default so if you are not using
anything from stdlibc++ the linker should remove it from the list of
dependencies. Gcc does have command line options like -nostdlib or
-nostdinc which could do what you want but I have never used them
myself for this so you'll need to try them out yourself.

As far as I know the option -Wl,--as-needed does not work for the libstdc++. Normally -nostdlib and -nostdinc are difficult to use because they omit very basic libraries like libgcc and libc. The approach of using gcc for linking and use -lsupc++ for c++ support is quite standard and supported by gcc.
 
But perhaps the biggest question is does the extra library really
matter? If you don't have a really good reason (such as something
breaking if you link with stdlibc++) then maybe it is simpler to just
let it do the default thing and not worry about it.

Ok, you are probalby right, I don't need to worry about that :-)

Thank very much your for your answer.

Kind regards
Francesco
Reply all
Reply to author
Forward
0 new messages