Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing definition of CXX11_ABI for gcc-like #10165

Merged
merged 3 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions conan/tools/cmake/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,9 @@ def context(self):
}.get(libcxx)
if lib:
lib = "-library={}".format(lib)
elif compiler == "gcc":
# we might want to remove this "1", it is the default in most distros
if libcxx == "libstdc++11":
glib = "1"
elif libcxx == "libstdc++":

if compiler in ['clang', 'apple-clang', 'gcc']:
if libcxx == "libstdc++":
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets be aware that from https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html

Using the default configuration options for GCC the default value of the macro is 1 which causes the new ABI to be active, so to use the old ABI you must explicitly define the macro to 0 before including any library headers. (Be aware that some GNU/Linux distributions configure GCC 5 differently so that the default value of the macro is 0 and users must define it to 1 to enable the new ABI.)

So if we go this way, users from those distros will need to customize the CMakeToolchain, something like this:

def generate(self):
    tc = CMakeToolchain(self)
    tc.blocks["libcxx"].values["glibcxx"] = "1" if self.settings.libcxx == "libstdc++11" else "0"
    tc.generate()

There were requests to eliminate the default GLIBCXX_USE_CXX11_ABI=1, as it was raising some warnings (undefined in some compilers, but not errors), so it seems there is no perfect solution for 100% of users.

glib = "0"
return {"set_libcxx": lib, "glibcxx": glib}

Expand Down
2 changes: 1 addition & 1 deletion conan/tools/gnu/autotoolstoolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def _cxx11_abi_define(self):
return

compiler = settings.get_safe("compiler.base") or settings.get_safe("compiler")
if compiler == "gcc":
if compiler in ['clang', 'apple-clang', 'gcc']:
if libcxx == 'libstdc++':
return '_GLIBCXX_USE_CXX11_ABI=0'

Expand Down
4 changes: 2 additions & 2 deletions conans/test/functional/toolchains/cmake/test_cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ def test_toolchain_linux(self, build_type, cppstd, arch, libcxx, shared):

extensions_str = "ON" if "gnu" in cppstd else "OFF"
arch_str = "-m32" if arch == "x86" else "-m64"
cxx11_abi_str = "1" if libcxx == "libstdc++11" else "0"
defines = '_GLIBCXX_USE_CXX11_ABI=%s;MYDEFINE="MYDEF_VALUE";MYDEFINEINT=42;'\
cxx11_abi_str = "_GLIBCXX_USE_CXX11_ABI=0;" if libcxx == "libstdc++" else ""
defines = '%sMYDEFINE="MYDEF_VALUE";MYDEFINEINT=42;'\
'MYDEFINE_CONFIG=$<IF:$<CONFIG:debug>,"MYDEF_DEBUG",$<IF:$<CONFIG:release>,'\
'"MYDEF_RELEASE","">>;MYDEFINEINT_CONFIG=$<IF:$<CONFIG:debug>,421,'\
'$<IF:$<CONFIG:release>,422,"">>' % cxx11_abi_str
Expand Down