core: add option to force compiling C++ as C++11
PATCH v2 1/1 core: add option to force compiling C++ as C++11
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.
--- Config.in | 17 +++++++++++++++++ package/Makefile.in | 10 +++++++++- 2 files changed, 26 insertions(+), 1 deletion(-)
Config.in +17 -0
@@ -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
package/Makefile.in +9 -1
@@ -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)
Signature · 1 line
2.6.2
PATCH v2 1/1 core: add option to force compiling C++ as C++11
Quoted 9 lines · Alexey Galakhov
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_CPP11configuration option that forces passing --std=c++11 to the compiler while building C++ target libraries.Signed-off-by Alexey Galakhov <[email protected]>
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
Quoted 57 lines
--- Config.in | 17 +++++++++++++++++ package/Makefile.in | 10 +++++++++- 2 files changed, 26 insertions(+), 1 deletion(-)Config.in +17
-0@@ -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_SHAREDpackage/Makefile.in +9
-1@@ -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)
Signature · 6 lines
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
PATCH v2 1/1 core: add option to force compiling C++ as C++11
Quoted 22 lines · On Fri, 4 Dec 2015 00:32:12 +0100 Arnout Vandecappelle <[email protected]> wrote:
Quoted 11 lines · Alexey Galakhov
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_CPP11configuration option that forces passing --std=c++11 to the compiler while building C++ target libraries.Signed-off-by Alexey Galakhov <[email protected]>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.
Quoted 2 lines
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
PATCH v2 1/1 core: add option to force compiling C++ as C++11
In reply to Alexey GalakhovHello,
Quoted 9 lines · Alexey Galakhov
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_CPP11configuration option that forces passing --std=c++11 to the compiler while building C++ target libraries.Signed-off-by Alexey Galakhov <[email protected]>
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
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com