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

redefinition error with gcc 5.1 #11

Closed
florian-wagner opened this issue Jun 2, 2015 · 11 comments
Closed

redefinition error with gcc 5.1 #11

florian-wagner opened this issue Jun 2, 2015 · 11 comments

Comments

@florian-wagner
Copy link

Compiling gccxml with gcc 5.1 raises the following error:

[ 70%] Building C object GCC/gcc/CMakeFiles/backend.dir/toplev.c.o
/home/fwagner/src/gimli/thirdParty/src/gccxml/GCC/gcc/toplev.c:546:1: Fehler: Redefinition von »floor_log2«
 floor_log2 (unsigned HOST_WIDE_INT x)
 ^
In file included from /home/fwagner/src/gimli/thirdParty/src/gccxml/GCC/gcc/toplev.c:59:0:
/home/fwagner/src/gimli/thirdParty/src/gccxml/GCC/gcc/toplev.h:174:1: Anmerkung: Vorherige Definition von »floor_log2« war hier
 floor_log2 (unsigned HOST_WIDE_INT x)
 ^
/home/fwagner/src/gimli/thirdParty/src/gccxml/GCC/gcc/toplev.c:581:1: Fehler: Redefinition von »exact_log2«
 exact_log2 (unsigned HOST_WIDE_INT x)
 ^
In file included from /home/fwagner/src/gimli/thirdParty/src/gccxml/GCC/gcc/toplev.c:59:0:
/home/fwagner/src/gimli/thirdParty/src/gccxml/GCC/gcc/toplev.h:180:1: Anmerkung: Vorherige Definition von »exact_log2« war hier
 exact_log2 (unsigned HOST_WIDE_INT x)
 ^
@iMichka
Copy link
Member

iMichka commented Jun 2, 2015

Hi. You should use https://github.com/CastXML/CastXML, which replaces gccxml and works with newer compilers).

@florian-wagner
Copy link
Author

I see, thanks a lot, looking forward pyplusplus' CastXML support.

@iMichka
Copy link
Member

iMichka commented Jun 3, 2015

I'm working on updating pygccxml which is needed by pyplusplus.
Most of the things already work but it will need some more tweaking. Hope to release a new version this summer.

@ppisar
Copy link

ppisar commented Sep 15, 2015

The issue is GCC/gcc/toplev.c defines floor_log2() if

/* When compiling with a recent enough GCC, we use the GNU C "extern inline"
   for floor_log2 and exact_log2; see toplev.h.  That construct, however,
   conflicts with the ISO C++ One Definition Rule.   */

#if GCC_VERSION < 3004 || !defined (__cplusplus)

but the GCC/gcc/toplev.c is compiled with a C compiler (cc), not C++ compiler. Therefore the preprocessor condition is true and the definition will clash with another definition in GCC/gcc/toplev.h:

/* Inline versions of the above for speed.  */
#if GCC_VERSION >= 3004
[...]
extern inline int
floor_log2 (unsigned HOST_WIDE_INT x)
{
  return x ? HOST_BITS_PER_WIDE_INT - 1 - (int) CLZ_HWI (x) : -1;
}

See this GCC commit https://gcc.gnu.org/ml/gcc-patches/2009-06/msg01249.html for potential solution.

@ppisar
Copy link

ppisar commented Sep 15, 2015

I think this patch will do:

From b08c89d503fe6fc5c3faf5cb896a4e6bcd837a4f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Tue, 15 Sep 2015 10:57:48 +0200
Subject: [PATCH] Avoid floor_log2() redefinition with C99
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

GCC 5.1 defaults to gnu11 which forbirs redefinitions. This patch
comes from <https://gcc.gnu.org/ml/gcc-patches/2009-06/msg01249.html>.

<https://github.com/gccxml/gccxml/issues/11>

Signed-off-by: Petr Písař <ppisar@redhat.com>
---
 GCC/gcc/toplev.c | 4 ++--
 GCC/gcc/toplev.h | 7 ++++---
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/GCC/gcc/toplev.c b/GCC/gcc/toplev.c
index 3526010..419dc00 100644
--- a/GCC/gcc/toplev.c
+++ b/GCC/gcc/toplev.c
@@ -537,7 +537,7 @@ read_integral_parameter (const char *p, const char *pname, const int  defval)
    for floor_log2 and exact_log2; see toplev.h.  That construct, however,
    conflicts with the ISO C++ One Definition Rule.   */

-#if GCC_VERSION < 3004 || !defined (__cplusplus)
+#if GCC_VERSION < 3004

 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
    If X is 0, return -1.  */
@@ -589,7 +589,7 @@ exact_log2 (unsigned HOST_WIDE_INT x)
 #endif
 }

-#endif /*  GCC_VERSION < 3004 || !defined (__cplusplus)  */
+#endif /*  GCC_VERSION < 3004 */

 /* Handler for fatal signals, such as SIGSEGV.  These are transformed
    into ICE messages, which is much more user friendly.  In case the
diff --git a/GCC/gcc/toplev.h b/GCC/gcc/toplev.h
index c935f7e..1edd5e5 100644
--- a/GCC/gcc/toplev.h
+++ b/GCC/gcc/toplev.h
@@ -151,6 +151,7 @@ extern void decode_d_option     (const char *);
 /* Return true iff flags are set as if -ffast-math.  */
 extern bool fast_math_flags_set_p  (void);

+#if GCC_VERSION < 3004
 /* Return log2, or -1 if not exact.  */
 extern int exact_log2                  (unsigned HOST_WIDE_INT);

@@ -158,7 +159,7 @@ extern int exact_log2                  (unsigned HOST_WIDE_INT);
 extern int floor_log2                  (unsigned HOST_WIDE_INT);

 /* Inline versions of the above for speed.  */
-#if GCC_VERSION >= 3004
+#else /* GCC_VERSION >= 3004 */
 # if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
 #  define CLZ_HWI __builtin_clzl
 #  define CTZ_HWI __builtin_ctzl
@@ -170,13 +171,13 @@ extern int floor_log2                  (unsigned HOST_WIDE_INT);
 #  define CTZ_HWI __builtin_ctz
 # endif

-extern inline int
+static inline int
 floor_log2 (unsigned HOST_WIDE_INT x)
 {
   return x ? HOST_BITS_PER_WIDE_INT - 1 - (int) CLZ_HWI (x) : -1;
 }

-extern inline int
+static inline int
 exact_log2 (unsigned HOST_WIDE_INT x)
 {
   return x == (x & -x) && x ? (int) CTZ_HWI (x) : -1;
-- 
2.4.3

@rohanpsingh
Copy link

Hey,

I have been facing the same issue. I have tried applying the patch shared by @ppisar
However even after making the changes the following error pops up:

multiple definition of `floor_log2'
../libbackend.a(tree-cfg.c.o):tree-cfg.c:(.text+0x1dac): first defined here

I have attached the toplevel.c and toplevel.h files in which the patch has been applied. (.c and .h have been converted to txt for upload)

I am working on installing pyplusplus

I figure this must be a problem with the gccxml or castxml versions.

Typing gccxml gives:
"
GCC-XML compatibility CastXML wrapper
Usage: gccxml [options] -fxml=

Note: not all the gccxml options are supported.
The real gccxml (not compatible with GCC 5) is available as gccxml.real.
"

Typing castxml -- version gives:
"
castxml version 0.1-g1489405

CastXML project maintained and supported by Kitware (kitware.com).

Ubuntu clang version 3.7.1-1ubuntu4 (tags/RELEASE_371/final) (based on LLVM 3.7.1)
Target: i686-pc-linux-gnu
Thread model: posix
"

My system is running 32 bit Ubuntu 16.04

please help, been stuck here since quite a while

toplev_c.txt
toplev_h.txt

@rohanpsingh
Copy link

Infact using the patch given above and compiling again throws this error::

CMakeFiles/gccxml_cc1plus.dir/except.c.o: In function nothrow_libfn_p': except.c:(.text+0x2444): undefined reference tolibc_name_p
CMakeFiles/gccxml_cc1plus.dir/__/c-common.c.o: In function resolve_overloaded_builtin': c-common.c:(.text+0x227dd): undefined reference toexact_log2'

@ppisar
Copy link

ppisar commented Jun 15, 2016

On Wed, Jun 15, 2016 at 04:41:37AM -0700, rohan565singh wrote:

I have been facing the same issue. I have tried applying the patch shared by
@ppisar However even after making the changes the following error pops up:

multiple definition of `floor_log2'
../libbackend.a(tree-cfg.c.o):tree-cfg.c:(.text+0x1dac): first defined here

It says tree-cfg.c contains yet another non-static definition of floor_log2
(maybe included from a header file). Search where it comes from. It may depend
on compiler options.

I have attached the toplevel.c and toplevel.h files in which the patch has
been applied. (.c and .h have been converted to txt for upload)

They seems to be patched correctly.

My system is running 32 bit Ubuntu 16.04

I don't know mutch about gccxml. My build enviroment was Fedora. You can see
here http://pkgs.fedoraproject.org/cgit/rpms/gccxml.git/tree/?h=f22 how it
was solved. My patch was used as the gccxml-gcc5.patch file there. Here
https://kojipkgs.fedoraproject.org//packages/gccxml/0.9.0/0.27.20150423.git3afa8ba.fc22/data/logs/x86_64/
are logs from building the code. The root.log lists all installed
dependencies, build.log is output of the build process. Maybe it helps you.

-- Petr

@rohanpsingh
Copy link

Hey,

Thanks for the reply. But the actual error seems to be this:

CMakeFiles/gccxml_cc1plus.dir/except.c.o: In function nothrow_libfn_p': except.c:(.text+0x2444): undefined reference tolibc_name_p
CMakeFiles/gccxml_cc1plus.dir/__/c-common.c.o: In function resolve_overloaded_builtin': c-common.c:(.text+0x227dd): undefined reference toexact_log2'

@firodj
Copy link

firodj commented Jul 12, 2016

may be this https://bugzilla.redhat.com/show_bug.cgi?id=476370 will resolve.

-D CMAKE_C_FLAGS=-fgnu89-inline

@daoerb
Copy link

daoerb commented Nov 28, 2019

cmake -D CMAKE_C_FLAGS=-fgnu89-inline ../gccxml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants