pygccxml icon indicating copy to clipboard operation
pygccxml copied to clipboard

Multiple Declaration Errors for namespace std in ARM

Open FireBoyAJ24 opened this issue 1 year ago • 1 comments

Description

When building the OMPL make update_bindings on ARM, we get an error: pygccxml.declarations.runtime_errors.multiple_declarations_found_t: Multiple declarations have been found. Matcher: [(decl type==namespace_t) and (name==std)]. Context of this issue comes from https://github.com/ompl/ompl/issues/1116.

Is it possible that the standard C++ library headers are treated differently (unexpectedly) in ARM compared to X86_64 in PygccXML?

I placed this issue in pygccxml as the error comes from this package compared to py++ and OMPL.

Expected Behavior

In X86_64, we are able to make the Python bindings with no errors. However, in ARM, we get the error stated in the description.

Example Code to Test the Error

from pygccxml import utils
from pygccxml import declarations
from pygccxml import parser
from pyplusplus import module_builder, messages
from pyplusplus.module_builder import call_policies

# Find the location of the xml generator (castxml or gccxml)
generator_path, generator_name = utils.find_xml_generator()

# Configure the xml generator
xml_generator_config = parser.xml_generator_configuration_t(
    xml_generator_path=generator_path,
    xml_generator=generator_name)

print(generator_name, generator_path)

name = "util"

mb = module_builder.module_builder_t(
            files=['util.h'],
            # cache is not used with compilation_mode = parser.COMPILATION_MODE.ALL_AT_ONCE
            # cache = '/workspaces/ompl_workspace/build/Release/pyplusplus_'+name+'.cache',
            xml_generator_config=xml_generator_config,
            compilation_mode=parser.COMPILATION_MODE.ALL_AT_ONCE,
            indexing_suite_version=2)
mb.classes().always_expose_using_scope = True
std_ns_decls = mb.namespace("std")

declarations.print_declarations(std_ns_decls)

Example util.h file:

// Copyright 2004-2006 Roman Yakovenko.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#ifndef __hello_world_hpp__
#define __hello_world_hpp__

#include <string>

//I want to rename color to Color
enum color{ red, green, blue };

struct genealogical_tree{/*...*/};

struct animal{

    explicit animal( const std::string& name="" )
    : m_name( name )
    {}

    //I need to set call policies to the function
    genealogical_tree& genealogical_tree_ref()
    { return m_genealogical_tree; }

    std::string name() const
    { return m_name; }

private:
    std::string m_name;
    genealogical_tree m_genealogical_tree;
};

//I want to exclude next declarations:
struct impl1{};
struct impl2{};

inline int* get_int_ptr(){ return 0;}
inline int* get_int_ptr(int){ return 0;}
inline int* get_int_ptr(double){ return 0;}

#endif//__hello_world_hpp__

Error:

Traceback (most recent call last):
  File "/workspaces/ompl_workspace/pyplusplus_test/generate_bindings.py", line 28, in <module>
    std_ns_decls = mb.namespace("std")
  File "/usr/local/lib/python3.10/dist-packages/pyplusplus/module_builder/module_builder.py", line 265, in namespace
    return self.global_ns.namespace( name=name
  File "/usr/local/lib/python3.10/dist-packages/pygccxml/declarations/namespace.py", line 117, in namespace
    self._find_single(
  File "/usr/local/lib/python3.10/dist-packages/pygccxml/declarations/scopedef.py", line 464, in _find_single
    found = matcher.get_single(decl_matcher, decls, False)
  File "/usr/local/lib/python3.10/dist-packages/pygccxml/declarations/scopedef.py", line 92, in get_single
    raise runtime_errors.multiple_declarations_found_t(decl_matcher)
pygccxml.declarations.runtime_errors.multiple_declarations_found_t: Multiple declarations have been found. Matcher: [(decl type==namespace_t) and (name==std)]

Tried Potential Solutions

  • We tried using different compilation modes (FILE_BY_FILE) instead of ALL_AT_ONCE and was able to build the util module but got the same multiple declaration error in other packages (base, geometric, etc).
  • We tried cache as well and got the same multiple declaration error.
  • We tried CastXML SuperBuild versions 0.6.5, 0.5.0 and 0.4.8. We still got the same multiple declaration error.
  • We tried 2.5.0 and 2.2.1 pygccxml and found the same error.
  • The error was found in Ubuntu Jammy.

Resources

  • https://github.com/ompl/ompl/issues/1116
  • https://github.com/UBCSailbot/sailbot_workspace/issues/398

FireBoyAJ24 avatar Sep 29 '24 05:09 FireBoyAJ24

Hey. Thanks for letting me know.

I think the best thing to do would be to have a minimal c/c++ code example to be able to reproduce this outside of the OMPL build context. So I can try to write a test case for it and debug it.

I do not have an ARM machine right now (might buy a ARM Mac next year though). I need to check if I can set ARM CI on Github, I think they announced ARM machines lately.

The bug might also be in CastXML. Another solution would be to provide the xml files that have been generated, because I think I can also explore their content and see what is going on.

iMichka avatar Oct 13 '24 08:10 iMichka

Hey. Thanks for letting me know.

I think the best thing to do would be to have a minimal c/c++ code example to be able to reproduce this outside of the OMPL build context. So I can try to write a test case for it and debug it.

I do not have an ARM machine right now (might buy a ARM Mac next year though). I need to check if I can set ARM CI on Github, I think they announced ARM machines lately.

The bug might also be in CastXML. Another solution would be to provide the xml files that have been generated, because I think I can also explore their content and see what is going on.

this errors occurs nowadays! Maybe you can accept my PR, and try to fix it

johnnynunez avatar Jan 31 '25 19:01 johnnynunez

@iMichka https://github.com/CastXML/pygccxml/pull/226

johnnynunez avatar Feb 01 '25 06:02 johnnynunez

I found a possible error try to add:

f"-DCMAKE_CXX_STANDARD=14",

johnnynunez avatar Feb 01 '25 18:02 johnnynunez

@johnnynunez thanks for all the hard work. I'm currently travelling, I'll have a look as soon as possible.

iMichka avatar Feb 03 '25 15:02 iMichka

thank you so much, I'm porting all libraries to arm, for digits... https://www.nvidia.com/en-us/project-digits/

johnnynunez avatar Feb 03 '25 15:02 johnnynunez

@iMichka do you know more about this?

johnnynunez avatar Feb 13 '25 01:02 johnnynunez

Description

When building the OMPL make update_bindings on ARM, we get an error: pygccxml.declarations.runtime_errors.multiple_declarations_found_t: Multiple declarations have been found. Matcher: [(decl type==namespace_t) and (name==std)]. Context of this issue comes from ompl/ompl#1116.

Is it possible that the standard C++ library headers are treated differently (unexpectedly) in ARM compared to X86_64 in PygccXML?

I placed this issue in pygccxml as the error comes from this package compared to py++ and OMPL.

Expected Behavior

In X86_64, we are able to make the Python bindings with no errors. However, in ARM, we get the error stated in the description.

Example Code to Test the Error

from pygccxml import utils
from pygccxml import declarations
from pygccxml import parser
from pyplusplus import module_builder, messages
from pyplusplus.module_builder import call_policies

# Find the location of the xml generator (castxml or gccxml)
generator_path, generator_name = utils.find_xml_generator()

# Configure the xml generator
xml_generator_config = parser.xml_generator_configuration_t(
    xml_generator_path=generator_path,
    xml_generator=generator_name)

print(generator_name, generator_path)

name = "util"

mb = module_builder.module_builder_t(
            files=['util.h'],
            # cache is not used with compilation_mode = parser.COMPILATION_MODE.ALL_AT_ONCE
            # cache = '/workspaces/ompl_workspace/build/Release/pyplusplus_'+name+'.cache',
            xml_generator_config=xml_generator_config,
            compilation_mode=parser.COMPILATION_MODE.ALL_AT_ONCE,
            indexing_suite_version=2)
mb.classes().always_expose_using_scope = True
std_ns_decls = mb.namespace("std")

declarations.print_declarations(std_ns_decls)

Example util.h file:

Error:

Traceback (most recent call last):
  File "/workspaces/ompl_workspace/pyplusplus_test/generate_bindings.py", line 28, in <module>
    std_ns_decls = mb.namespace("std")
  File "/usr/local/lib/python3.10/dist-packages/pyplusplus/module_builder/module_builder.py", line 265, in namespace
    return self.global_ns.namespace( name=name
  File "/usr/local/lib/python3.10/dist-packages/pygccxml/declarations/namespace.py", line 117, in namespace
    self._find_single(
  File "/usr/local/lib/python3.10/dist-packages/pygccxml/declarations/scopedef.py", line 464, in _find_single
    found = matcher.get_single(decl_matcher, decls, False)
  File "/usr/local/lib/python3.10/dist-packages/pygccxml/declarations/scopedef.py", line 92, in get_single
    raise runtime_errors.multiple_declarations_found_t(decl_matcher)
pygccxml.declarations.runtime_errors.multiple_declarations_found_t: Multiple declarations have been found. Matcher: [(decl type==namespace_t) and (name==std)]

Tried Potential Solutions

  • We tried using different compilation modes (FILE_BY_FILE) instead of ALL_AT_ONCE and was able to build the util module but got the same multiple declaration error in other packages (base, geometric, etc).
  • We tried cache as well and got the same multiple declaration error.
  • We tried CastXML SuperBuild versions 0.6.5, 0.5.0 and 0.4.8. We still got the same multiple declaration error.
  • We tried 2.5.0 and 2.2.1 pygccxml and found the same error.
  • The error was found in Ubuntu Jammy.

Resources

I found this error with latest castxml. Not only appears in ARM

johnnynunez avatar Feb 17 '25 18:02 johnnynunez

it is working https://github.com/johnnynunez/ompl/actions/runs/13643981441 close :)

johnnynunez avatar Mar 04 '25 02:03 johnnynunez

This is fixed with pygccxml 3.0.0

iMichka avatar Mar 11 '25 20:03 iMichka