0

I'm using pybindgen to create the link code between python and c++. Or at least I would be if I could get it to work with my code. The python file when run produces the following errors. Any way by which I could satisfy pybindgen or resolve these issues would be extremely helpful.

pygccxml.parser.source_reader.gccxml_runtime_error_t: Error occured while running GCC-XML: In file included from c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/cstdio:44,
                 from c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/fstream:43,
                 from C:\Users\Richard\workspace\PyBindGen\src\/tokeniser.hpp:13,
                 from C:\Users\Richard\workspace\PyBindGen\src\/includes.hpp:11,
                 from C:\Users\Richard\workspace\PyBindGen\src\file.hpp:9:
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../include/stdio.h:191: error: reference to 'size_t' is ambiguous
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/stddef.h:212: error: candidates are: typedef unsigned int size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/mingw32/bits/c++config.h:155: error:                 typedef unsigned int std::size_t
... [some recuring size_t errors removed because size too big]

c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../include/stdio.h:413: error: expected constructor, destructor, or type conversion before 'fwrite'
In file included from c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/fstream:43,
                 from C:\Users\Richard\workspace\PyBindGen\src\/tokeniser.hpp:13,
                 from C:\Users\Richard\workspace\PyBindGen\src\/includes.hpp:11,
                 from C:\Users\Richard\workspace\PyBindGen\src\file.hpp:9:
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/cstdio:109: error: '::fread' has not been declared
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/cstdio:115: error: '::fwrite' has not been declared
In file included from C:\Users\Richard\workspace\PyBindGen\src\/tokeniser.hpp:14,
                 from C:\Users\Richard\workspace\PyBindGen\src\/includes.hpp:11,
                 from C:\Users\Richard\workspace\PyBindGen\src\file.hpp:9:
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../include/stdlib.h:345: error: reference to 'size_t' is ambiguous
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/stddef.h:212: error: candidates are: typedef unsigned int size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/mingw32/bits/c++config.h:155: error:                 typedef unsigned int std::size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../include/stdlib.h:345: error: expected constructor, destructor, or type conversion before 'wcstombs'
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../include/stdlib.h:348: error: reference to 'size_t' is ambiguous
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/stddef.h:212: error: candidates are: typedef unsigned int size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/mingw32/bits/c++config.h:155: error:                 typedef unsigned int std::size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../include/stdlib.h:348: error: reference to 'size_t' is ambiguous
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/stddef.h:212: error: candidates are: typedef unsigned int size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/mingw32/bits/c++config.h:155: error:                 typedef unsigned int std::size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../include/stdlib.h:348: error: 'size_t' has not been declared
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../include/stdlib.h:349: error: reference to 'size_t' is ambiguous
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/stddef.h:212: error: candidates are: typedef unsigned int size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/mingw32/bits/c++config.h:155: error:                 typedef unsigned int std::size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../include/stdlib.h:349: error: expected constructor, destructor, or type conversion before 'mbstowcs'
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../include/stdlib.h:350: error: reference to 'size_t' is ambiguous
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/stddef.h:212: error: candidates are: typedef unsigned int size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/mingw32/bits/c++config.h:155: error:                 typedef unsigned int std::size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../include/stdlib.h:350: error: reference to 'size_t' is ambiguous
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/stddef.h:212: error: candidates are: typedef unsigned int size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/mingw32/bits/c++config.h:155: error:                 typedef unsigned int std::size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../include/stdlib.h:350: error: 'size_t' has not been declared
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../include/stdlib.h:355: error: reference to 'size_t' is ambiguous
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/stddef.h:212: error: candidates are: typedef unsigned int size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/mingw32/bits/c++config.h:155: error:                 typedef unsigned int std::size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../include/stdlib.h:355: error: reference to 'size_t' is ambiguous
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/stddef.h:212: error: candidates are: typedef unsigned int size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/mingw32/bits/c++config.h:155: error:                 typedef unsigned int std::size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../include/stdlib.h:355: error: reference to 'size_t' is ambiguous
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/stddef.h:212: error: candidates are: typedef unsigned int size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/mingw32/bits/c++config.h:155: error:                 typedef unsigned int std::size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../include/stdlib.h:355: error: reference to 'size_t' is ambiguous
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/stddef.h:212: error: candidates are: typedef unsigned int size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/mingw32/bits/c++config.h:155: error:                 typedef unsigned int std::size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../include/stdlib.h:355: error: initializer expression list treated as compound expression
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../include/stdlib.h:356: error: reference to 'size_t' is ambiguous
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/stddef.h:212: error: candidates are: typedef unsigned int size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/mingw32/bits/c++config.h:155: error:                 typedef unsigned int std::size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../include/stdlib.h:356: error: reference to 'size_t' is ambiguous
... [some recuring size_t errors removed because size too big]
In file included from c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/cstring:44,
                 from C:/Users/Richard/Desktop/code/boost_1_51_0/boost/lexical_cast.hpp:32,
                 from C:\Users\Richard\workspace\PyBindGen\src\/dataitem.hpp:9,
                 from C:\Users\Richard\workspace\PyBindGen\src\/includes.hpp:24,
                 from C:\Users\Richard\workspace\PyBindGen\src\file.hpp:9:
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../include/string.h:36: error: reference to 'size_t' is ambiguous
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/stddef.h:212: error: candidates are: typedef unsigned int size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/mingw32/bits/c++config.h:155: error:                 typedef unsigned int std::size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../include/string.h:36: error: reference to 'size_t' is ambiguous
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/stddef.h:212: error: candidates are: typedef unsigned int size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/mingw32/bits/c++config.h:155: error:                 typedef unsigned int std::size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../include/string.h:36: error: 'size_t' has not been declared
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../include/string.h:37: error: reference to 'size_t' is ambiguous
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/stddef.h:212: error: candidates are: typedef unsigned int size_t
... [some recuring size_t errors removed because size too big]
In file included from C:/Users/Richard/Desktop/code/boost_1_51_0/boost/lexical_cast.hpp:32,
                 from C:\Users\Richard\workspace\PyBindGen\src\/dataitem.hpp:9,
                 from C:\Users\Richard\workspace\PyBindGen\src\/includes.hpp:24,
                 from C:\Users\Richard\workspace\PyBindGen\src\file.hpp:9:
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/cstring:86: error: '::strcspn' has not been declared
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/cstring:88: error: '::strlen' has not been declared
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/cstring:92: error: '::strspn' has not been declared
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/cstring:94: error: '::strxfrm' has not been declared
In file included from c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/ctime:44,
                 from c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/bits/locale_facets_nonio.h:39,
                 from c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/locale:43,
                 from C:/Users/Richard/Desktop/code/boost_1_51_0/boost/lexical_cast.hpp:47,
                 from C:\Users\Richard\workspace\PyBindGen\src\/dataitem.hpp:9,
                 from C:\Users\Richard\workspace\PyBindGen\src\/includes.hpp:24,
                 from C:\Users\Richard\workspace\PyBindGen\src\file.hpp:9:
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../include/time.h:124: error: reference to 'size_t' is ambiguous
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/stddef.h:212: error: candidates are: typedef unsigned int size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/mingw32/bits/c++config.h:155: error:                 typedef unsigned int std::size_t
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../include/time.h:124: error: expected constructor, destructor, or type conversion before 'strftime'
In file included from c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/bits/locale_facets_nonio.h:39,
                 from c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/locale:43,
                 from C:/Users/Richard/Desktop/code/boost_1_51_0/boost/lexical_cast.hpp:47,
                 from C:\Users\Richard\workspace\PyBindGen\src\/dataitem.hpp:9,
                 from C:\Users\Richard\workspace\PyBindGen\src\/includes.hpp:24,
                 from C:\Users\Richard\workspace\PyBindGen\src\file.hpp:9:
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/ctime:74: error: '::strftime' has not been declared
In file included from C:/Users/Richard/Desktop/code/boost_1_51_0/boost/assert.hpp:81,
                 from C:/Users/Richard/Desktop/code/boost_1_51_0/boost/array.hpp:44,
                 from C:/Users/Richard/Desktop/code/boost_1_51_0/boost/lexical_cast.hpp:146,
                 from C:\Users\Richard\workspace\PyBindGen\src\/dataitem.hpp:9,
                 from C:\Users\Richard\workspace\PyBindGen\src\/includes.hpp:24,
                 from C:\Users\Richard\workspace\PyBindGen\src\file.hpp:9:
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/cstdlib:122: error: '::mbstowcs' has not been declared
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/cstdlib:134: error: '::wcstombs' has not been declared
In file included from C:/Users/Richard/Desktop/code/boost_1_51_0/boost/range/end.hpp:24,
                 from C:/Users/Richard/Desktop/code/boost_1_51_0/boost/range/functions.hpp:19,
                 from C:/Users/Richard/Desktop/code/boost_1_51_0/boost/range/iterator_range_core.hpp:26,
                 from C:/Users/Richard/Desktop/code/boost_1_51_0/boost/lexical_cast.hpp:155,
                 from C:\Users\Richard\workspace\PyBindGen\src\/dataitem.hpp:9,
                 from C:\Users\Richard\workspace\PyBindGen\src\/includes.hpp:24,
                 from C:\Users\Richard\workspace\PyBindGen\src\file.hpp:9:
C:/Users/Richard/Desktop/code/boost_1_51_0/boost/range/detail/implementation_help.hpp: In function 'const char* boost::range_detail::str_end(const char*, const char*)':
C:/Users/Richard/Desktop/code/boost_1_51_0/boost/range/detail/implementation_help.hpp:37: error: 'strlen' was not declared in this scope

My .py file is

#! /usr/bin/env python

import sys
import os

import pybindgen
from pybindgen.typehandlers import base as typehandlers
from pybindgen import (ReturnValue, Parameter, Module, Function, FileCodeSink)
from pybindgen import (CppMethod, CppConstructor, CppClass, Enum)
from pybindgen.gccxmlparser import ModuleParser
from pybindgen.function import CustomFunctionWrapper
from pybindgen.cppmethod import CustomCppMethodWrapper

import generator_common

def my_module_gen():
    out = FileCodeSink(sys.stdout)
    pygen_file = open(sys.argv[2], "wt")
    module_parser = ModuleParser('eyon', '::')
    module_parser.enable_anonymous_containers = True

    module = module_parser.parse([sys.argv[1]], includes=['"file.hpp"'], pygen_sink=FileCodeSink(pygen_file),
                                 include_paths=["C:\\Users\\Richard\\Desktop\\code\\boost_1_51_0"])
    pygen_file.close()

    generator_common.customize_module(module)

    module.generate(out)


def main():
    if sys.argv[1] == '-d':
        del sys.argv[1]
        import pdb
        pdb.set_trace()
        my_module_gen()
    else:
        import os
        if "PYBINDGEN_ENABLE_PROFILING" in os.environ:
            try:
                import cProfile as profile
            except ImportError:
                my_module_gen()
            else:
                print >> sys.stderr, "** running under profiler"
                profile.run('my_module_gen()', 'foomodulegen-auto.pstat')
        else:
            my_module_gen()            

if __name__ == '__main__':
    main()
hochl
  • 12,524
  • 10
  • 53
  • 87
ceorron
  • 1,230
  • 1
  • 17
  • 28
  • No one is going to bother reading your wall of errors and code. Please post a short example that reproduces your problem. – Tony The Lion Oct 02 '12 at 12:58
  • 1
    I did post the code that reproduces the problems. If you know pybindgen better than I then I assume these errors must be pretty common and so an easy fix? – ceorron Oct 02 '12 at 13:10
  • I think your minGW install is broken. Does it compile simple C++ files ? – slaphappy Oct 02 '12 at 13:14
  • Yes it compiles the source that this code is trying to generate using. It is not broken, I use it daily. – ceorron Oct 02 '12 at 13:16
  • @ceorron: What makes you think that? Just because he might know pybindgen better doesn't at all mean that your errors must be common. In fact, the knowledge level of the person trying to help you is completely orthogonal to the difficulty of solving your problem. – Puppy Oct 02 '12 at 13:26
  • I suppose I am assuming that other may know more because I am new to python and pybindgen. If the errors ain't common, then I have a real problem. Possibly as mentioned a bug in MinGW and/or a bug in pybindgen. If I can't find a way to overcome them myself then I may have to do some back tracking. In other words not using pybindgen. – ceorron Oct 02 '12 at 13:36

2 Answers2

0

Just a guess, but from your error message, you might have a pathing issue. Note the path marker between src and tokeniser. C:\Users\Richard\workspace\PyBindGen\src\/tokeniser.hpp:13

BigHandsome
  • 4,843
  • 5
  • 23
  • 30
0

This wasn't an easy work around but here it is.

I removed all the "using namespace std;" and any other "using" items from my code so instead used "std::" for anything from the standard library. This got rid of the size_t name conflict issue. This seemed to sort out a lot and is probably a c++ standard/MinGW implementation of the standard library not working well with GCC_XML. In other words the c++ standard permits namespace declarations that GCC_XML can't understand and so you get conflicts.

Note this doesn't seem to effect having things in namespaces. So this works fine.

namespace Hello
{
    void func()
    {
        printf("Hello World");
    }
}

The other issues came from me not declaring enough to pybindgen about the boost library dependency. Here is the modified .py file.

#! /usr/bin/env python

import sys
import os

import pybindgen
from pybindgen.typehandlers import base as typehandlers
from pybindgen import (ReturnValue, Parameter, Module, param, Function, FileCodeSink)
from pybindgen import (CppMethod, CppConstructor, CppClass, Enum)
from pybindgen.gccxmlparser import ModuleParser
from pybindgen.function import CustomFunctionWrapper
from pybindgen.cppmethod import CustomCppMethodWrapper

import generator_common

def my_module_gen():
    out = FileCodeSink(sys.stdout)
    pygen_file = open(sys.argv[2], "wt")

    #setup the module
    module = Module('eyon', cpp_namespace='::')
    module.add_include('"file.hpp"')
    module.add_include('"boost/lexical_cast.hpp"')

    module_parser = ModuleParser('eyon', '::')
    module_parser.enable_anonymous_containers = True

    module = module_parser.parse([sys.argv[1]], includes=['"file.hpp"'], pygen_sink=FileCodeSink(pygen_file),
                                 include_paths=["C:\\Users\\Richard\\Desktop\\code\\boost_1_51_0"])
    pygen_file.close()

    module.generate(out)


def main():
    if sys.argv[1] == '-d':
        del sys.argv[1]
        import pdb
        pdb.set_trace()
        my_module_gen()
    else:
        import os
        if "PYBINDGEN_ENABLE_PROFILING" in os.environ:
            try:
                import cProfile as profile
            except ImportError:
                my_module_gen()
            else:
                print >> sys.stderr, "** running under profiler"
                profile.run('my_module_gen()', 'foomodulegen-auto.pstat')
        else:
            my_module_gen()            

if __name__ == '__main__':
    main()
ceorron
  • 1,230
  • 1
  • 17
  • 28