2010-09-30 33 views
0

我試圖將C頭轉換爲使用ctypes和ctypeslib的Python庫。我在OSX 10.6.4(Snow Leopard)上運行Python 2.7。
我正在轉換的頭文件是mcbcio32.h,位於/header/mcbcio32.h 我希望在同一個文件夾中創建一個名爲mcbcio32.xml的xml輸出。提高child_exception Errno 2

我請從ctypeslib夾h2xml.py(其中C頭轉換成包裹xml文件)用下面的命令:

$蟒h2xml.py /header/mcbcio32.h -o mcbcio32.xml -q -c

輸出:

Traceback (most recent call last): 
    File "h2xml.py", line 92, in <module> 
    sys.exit(main()) 
    File "h2xml.py", line 86, in main 
    compile_to_xml(argv) 
    File "h2xml.py", line 79, in compile_to_xml 
    parser.parse(files) 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypeslib/codegen/cparser.py", line 306, in parse 
    self.create_final_xml(include_files, types, None) 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypeslib/codegen/cparser.py", line 265, in create_final_xml 
    self.create_xml(source, xmlfile) 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypeslib/codegen/cparser.py", line 97, in create_xml 
    stdin=subprocess.PIPE) 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 672, in __init__ 
    errread, errwrite) 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1201, in _execute_child 
    raise child_exception 
OSError: [Errno 2] No such file or directory 

從我可以告訴,三個主要的腳本時,h2xml.py,cparser.py叫,最後subprocess.py。所有這些腳本都是由Python開發人員編寫的,因此我猜測錯誤在於我如何運行發佈命令。

h2xml.py代碼:

"""h2xml - convert C include file(s) into an xml file by running gccxml.""" 
import sys, os, ConfigParser 
from ctypeslib.codegen import cparser 
from optparse import OptionParser 

def compile_to_xml(argv): 
    def add_option(option, opt, value, parser): 
     parser.values.gccxml_options.extend((opt, value)) 

    # Hm, should there be a way to disable the config file? 
    # And then, this should be done AFTER the parameters are processed. 
    config = ConfigParser.ConfigParser() 
    try: 
     config.read("h2xml.cfg") 
    except ConfigParser.ParsingError, detail: 
     print >> sys.stderr, detail 
     return 1 

    parser = OptionParser("usage: %prog includefile ... [options]") 
    parser.add_option("-q", "--quiet", 
         dest="quiet", 
         action="store_true", 
         default=False) 

    parser.add_option("-D", 
         type="string", 
         action="callback", 
         callback=add_option, 
         dest="gccxml_options", 
         help="macros to define", 
         metavar="NAME[=VALUE]", 
         default=[]) 

    parser.add_option("-U", 
         type="string", 
         action="callback", 
         callback=add_option, 
         help="macros to undefine", 
         metavar="NAME") 

    parser.add_option("-I", 
         type="string", 
         action="callback", 
         callback=add_option, 
         dest="gccxml_options", 
         help="additional include directories", 
         metavar="DIRECTORY") 

    parser.add_option("-o", 
         dest="xmlfile", 
         help="XML output filename", 
         default=None) 

    parser.add_option("-c", "--cpp-symbols", 
         dest="cpp_symbols", 
         action="store_true", 
         help="try to find #define symbols - this may give compiler errors, " \ 
         "so it's off by default.", 
         default=False) 

    parser.add_option("-k", 
         dest="keep_temporary_files", 
         action="store_true", 
         help="don't delete the temporary files created "\ 
         "(useful for finding problems)", 
         default=False) 

    options, files = parser.parse_args(argv[1:]) 

    if not files: 
     print "Error: no files to process" 
     print >> sys.stderr, __doc__ 
     return 1 

    options.flags = options.gccxml_options 
    options.verbose = not options.quiet 

    parser = cparser.IncludeParser(options) 
    parser.parse(files) 

def main(argv=None): 
    if argv is None: 
     argv = sys.argv 

    try: 
     compile_to_xml(argv) 
    except cparser.CompilerError, detail: 
     print >> sys.stderr, "CompilerError:", detail 
     return 1 

if __name__ == "__main__": 
    sys.exit(main()) 

我已經安裝GCC-XML和ctypeslib被粘貼到: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ (我的本地Python庫路徑)

如果有任何其他信息會有用,請讓我知道。預先感謝您的幫助。

回答

1

問題出在安裝gcc-xml。確保安裝gcc-xml以安裝cmake功能(cmake.org)。在gcc安裝文件夾中正確使用cmake解決了我遇到的所有目錄問題。

相關問題