All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH v2 1/1] core: add option to force compiling C++ as C++11
@ 2015-11-30 14:19 Alexey Galakhov
  2015-12-03 23:32 ` Arnout Vandecappelle
  2016-04-15 20:28 ` Thomas Petazzoni
  0 siblings, 2 replies; 4+ messages in thread
From: Alexey Galakhov @ 2015-11-30 14:19 UTC (permalink / raw)
  To: buildroot

Many C++ libraries like boost and log4cplus use defines to be compatible with
both C++03 and C++11 standards. This causes ABI incompatibilities between
a library built with C++03 and an application built with C++11. To avoid this,
one has to built libraries as C++11 as well.

This patch introduces the BR2_ENABLE_CPP11 configuration option that forces
passing --std=c++11 to the compiler while building C++ target libraries.

Signed-off-by: Alexey Galakhov <agalakhov@gmail.com>
---
 Config.in           | 17 +++++++++++++++++
 package/Makefile.in | 10 +++++++++-
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/Config.in b/Config.in
index d795361..1ee2ca3 100644
--- a/Config.in
+++ b/Config.in
@@ -533,6 +533,23 @@ config BR2_ENABLE_SSP
 comment "enabling Stack Smashing Protection requires support in the toolchain"
 	depends on !BR2_TOOLCHAIN_HAS_SSP
 
+config BR2_ENABLE_CPP11
+	bool "force C++11 when building libraries"
+	default n
+	depends on BR2_INSTALL_LIBSTDCPP
+	depends on BR2_TOOLCHAIN_GCC_AT_LEAST_4_3
+	help
+	  Force building of C++ libraries in C++11 mode.
+
+	  Some C++ libraries (i.e. boost) behave differently if compiled with
+	  and without --std=c++11 flag. They define classes differently. This
+	  causes linker errors while trying to use such a library in a C++11
+	  project.
+
+	  This option forces building of all such libraries in C++11 mode.
+	  Enable it if you encounter C++11-related linker errors while building
+	  your own or some 3rd-party software against buildroot libraries.
+
 choice
 	bool "libraries"
 	default BR2_SHARED_LIBS if BR2_BINFMT_SUPPORTS_SHARED
diff --git a/package/Makefile.in b/package/Makefile.in
index 85008bb..0cca97e 100644
--- a/package/Makefile.in
+++ b/package/Makefile.in
@@ -135,9 +135,17 @@ ifeq ($(BR2_DEBUG_3),y)
 TARGET_DEBUGGING = -g3
 endif
 
+ifeq ($(BR2_ENABLE_CPP11),y)
+ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_4_7),y)
+TARGET_CXXLANGUAGE = --std=c++11
+else
+TARGET_CXXLANGUAGE = --std=c++0x
+endif
+endif
+
 TARGET_CPPFLAGS += -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
 TARGET_CFLAGS = $(TARGET_CPPFLAGS) $(TARGET_ABI) $(TARGET_OPTIMIZATION) $(TARGET_DEBUGGING)
-TARGET_CXXFLAGS = $(TARGET_CFLAGS)
+TARGET_CXXFLAGS = $(TARGET_CFLAGS) $(TARGET_CXXLANGUAGE)
 TARGET_LDFLAGS = $(call qstrip,$(BR2_TARGET_LDFLAGS))
 
 ifeq ($(BR2_BINFMT_FLAT),y)
-- 
2.6.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Buildroot] [PATCH v2 1/1] core: add option to force compiling C++ as C++11
  2015-11-30 14:19 [Buildroot] [PATCH v2 1/1] core: add option to force compiling C++ as C++11 Alexey Galakhov
@ 2015-12-03 23:32 ` Arnout Vandecappelle
  2015-12-07 20:48   ` Alexey Galakhov
  2016-04-15 20:28 ` Thomas Petazzoni
  1 sibling, 1 reply; 4+ messages in thread
From: Arnout Vandecappelle @ 2015-12-03 23:32 UTC (permalink / raw)
  To: buildroot

On 30-11-15 15:19, Alexey Galakhov wrote:
> Many C++ libraries like boost and log4cplus use defines to be compatible with
> both C++03 and C++11 standards. This causes ABI incompatibilities between
> a library built with C++03 and an application built with C++11. To avoid this,
> one has to built libraries as C++11 as well.
> 
> This patch introduces the BR2_ENABLE_CPP11 configuration option that forces
> passing --std=c++11 to the compiler while building C++ target libraries.
> 
> Signed-off-by: Alexey Galakhov <agalakhov@gmail.com>

 Hi Alexey,

 I've been mulling about this for some time and I'm not sure if we really want
this. First of all, as I wrote before, it should probably be done automatically
somehow instead of being user-selectable. However, I'm also afraid that some
packages will fail to build with --std=c++11. Since we will not enable this
option in the autobuilders, we will not notice such problems.

 Do you know of other packages (other than boost) that expose this problem?
Perhaps instead we should add an option to boost only?

 Regards,
 Arnout

> ---
>  Config.in           | 17 +++++++++++++++++
>  package/Makefile.in | 10 +++++++++-
>  2 files changed, 26 insertions(+), 1 deletion(-)
> 
> diff --git a/Config.in b/Config.in
> index d795361..1ee2ca3 100644
> --- a/Config.in
> +++ b/Config.in
> @@ -533,6 +533,23 @@ config BR2_ENABLE_SSP
>  comment "enabling Stack Smashing Protection requires support in the toolchain"
>  	depends on !BR2_TOOLCHAIN_HAS_SSP
>  
> +config BR2_ENABLE_CPP11
> +	bool "force C++11 when building libraries"
> +	default n
> +	depends on BR2_INSTALL_LIBSTDCPP
> +	depends on BR2_TOOLCHAIN_GCC_AT_LEAST_4_3
> +	help
> +	  Force building of C++ libraries in C++11 mode.
> +
> +	  Some C++ libraries (i.e. boost) behave differently if compiled with
> +	  and without --std=c++11 flag. They define classes differently. This
> +	  causes linker errors while trying to use such a library in a C++11
> +	  project.
> +
> +	  This option forces building of all such libraries in C++11 mode.
> +	  Enable it if you encounter C++11-related linker errors while building
> +	  your own or some 3rd-party software against buildroot libraries.
> +
>  choice
>  	bool "libraries"
>  	default BR2_SHARED_LIBS if BR2_BINFMT_SUPPORTS_SHARED
> diff --git a/package/Makefile.in b/package/Makefile.in
> index 85008bb..0cca97e 100644
> --- a/package/Makefile.in
> +++ b/package/Makefile.in
> @@ -135,9 +135,17 @@ ifeq ($(BR2_DEBUG_3),y)
>  TARGET_DEBUGGING = -g3
>  endif
>  
> +ifeq ($(BR2_ENABLE_CPP11),y)
> +ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_4_7),y)
> +TARGET_CXXLANGUAGE = --std=c++11
> +else
> +TARGET_CXXLANGUAGE = --std=c++0x
> +endif
> +endif
> +
>  TARGET_CPPFLAGS += -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
>  TARGET_CFLAGS = $(TARGET_CPPFLAGS) $(TARGET_ABI) $(TARGET_OPTIMIZATION) $(TARGET_DEBUGGING)
> -TARGET_CXXFLAGS = $(TARGET_CFLAGS)
> +TARGET_CXXFLAGS = $(TARGET_CFLAGS) $(TARGET_CXXLANGUAGE)
>  TARGET_LDFLAGS = $(call qstrip,$(BR2_TARGET_LDFLAGS))
>  
>  ifeq ($(BR2_BINFMT_FLAT),y)
> 


-- 
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Buildroot] [PATCH v2 1/1] core: add option to force compiling C++ as C++11
  2015-12-03 23:32 ` Arnout Vandecappelle
@ 2015-12-07 20:48   ` Alexey Galakhov
  0 siblings, 0 replies; 4+ messages in thread
From: Alexey Galakhov @ 2015-12-07 20:48 UTC (permalink / raw)
  To: buildroot

On Fri, 4 Dec 2015 00:32:12 +0100
Arnout Vandecappelle <arnout@mind.be> wrote:

> On 30-11-15 15:19, Alexey Galakhov wrote:
> > Many C++ libraries like boost and log4cplus use defines to be
> > compatible with both C++03 and C++11 standards. This causes ABI
> > incompatibilities between a library built with C++03 and an
> > application built with C++11. To avoid this, one has to built
> > libraries as C++11 as well.
> > 
> > This patch introduces the BR2_ENABLE_CPP11 configuration option
> > that forces passing --std=c++11 to the compiler while building C++
> > target libraries.
> > 
> > Signed-off-by: Alexey Galakhov <agalakhov@gmail.com>  
> 
>  Hi Alexey,
> 
>  I've been mulling about this for some time and I'm not sure if we
> really want this. First of all, as I wrote before, it should probably
> be done automatically somehow instead of being user-selectable.
> However, I'm also afraid that some packages will fail to build with
> --std=c++11. Since we will not enable this option in the
> autobuilders, we will not notice such problems.
> 
>  Do you know of other packages (other than boost) that expose this
> problem? Perhaps instead we should add an option to boost only?

Hi Arnout,

At least log4cplus suffers from the same problem. Theoretically it
should affect every package that uses move constructors and checks the
version using the __cplusplus macro.

Unfortunately, it is impossible to do this not user-selectable. The
correct setting depends upon third-party programs installed on top of
the buildroot, and we have no way to determine the correct settings for
them.

We may override this option on per-package basis in case it gives
compilation problems. Theoretically any modern compiler should work
fine even with legacy code in C++11 mode, so it should be more or less
safe to enable C++11 for everything.

Regards,
Alexey

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Buildroot] [PATCH v2 1/1] core: add option to force compiling C++ as C++11
  2015-11-30 14:19 [Buildroot] [PATCH v2 1/1] core: add option to force compiling C++ as C++11 Alexey Galakhov
  2015-12-03 23:32 ` Arnout Vandecappelle
@ 2016-04-15 20:28 ` Thomas Petazzoni
  1 sibling, 0 replies; 4+ messages in thread
From: Thomas Petazzoni @ 2016-04-15 20:28 UTC (permalink / raw)
  To: buildroot

Hello,

On Mon, 30 Nov 2015 15:19:36 +0100, Alexey Galakhov wrote:
> Many C++ libraries like boost and log4cplus use defines to be compatible with
> both C++03 and C++11 standards. This causes ABI incompatibilities between
> a library built with C++03 and an application built with C++11. To avoid this,
> one has to built libraries as C++11 as well.
> 
> This patch introduces the BR2_ENABLE_CPP11 configuration option that forces
> passing --std=c++11 to the compiler while building C++ target libraries.
> 
> Signed-off-by: Alexey Galakhov <agalakhov@gmail.com>

Following the feedback from Arnout, I've marked this patch as Rejected
in our patch tracking system. The issue should be solved on a
per-package basis.

Thanks!

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-04-15 20:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-30 14:19 [Buildroot] [PATCH v2 1/1] core: add option to force compiling C++ as C++11 Alexey Galakhov
2015-12-03 23:32 ` Arnout Vandecappelle
2015-12-07 20:48   ` Alexey Galakhov
2016-04-15 20:28 ` Thomas Petazzoni

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.