当我使用py 生成时,然后在macOS上boost.python包装器时,我会发现有关std :: string的错

When I use py++ to generate then boost.Python wrapper on macOS, I got a error about std::string?

本文关键字:包装 发现 的错 string std python py 然后 macOS boost      更新时间:2023-10-16

我要生成的代码

#include <string>
#include <iostream>
class Dog
{
public:
  Dog(int age, std::string name):age_(age),name_(name){}
  void bark()
  {
      std::cout<<"Wang! Wang!"<<std::endl;
  }
private:
  int age_;
  std::string name_;
};

生成的python代码如下:

from pygccxml import parser
from pyplusplus import module_builder
generator_path="/usr/local/bin/castxml"
generator_name="castxml"
compiler="clang++"
compiler_path="/usr/bin/clang++"
xml_generator_config=parser.xml_generator_configuration_t(xml_generator_path=generator_path,
                                                   xml_generator=generator_name,
                                                    compiler=compiler,
                                                   compiler_path=compiler_path)
header_collection=["Bonjour.hpp"]
builder=module_builder.module_builder_t(header_collection,xml_generator_path=generator_path,
                                        xml_generator_config=xml_generator_config)
builder.classes().add_properties(exclude_accessors=True)
builder.build_code_creator(module_name="pylib_auto")
builder.write_module('pylib_auto.cpp')

我用命令运行:

python3 pylib_generator.py

我得到了以下错误:

    INFO Parsing source file "Bonjour.hpp" ...
    In file included from Bonjour.hpp:1:
    In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/string:469:
    /Library/Developer/CommandLineTools/usr/include/c++/v1/__config:235:11: fatal error: 'endian.h' file not found
    # include <endian.h>
              ^~~~~~~~~~
    1 error generated.
    Traceback (most recent call last):
      File "pylib_generator.py", line 17, in <module>
        xml_generator_config=xml_generator_config)
      File "/usr/local/lib/python3.6/site-packages/pyplusplus/module_builder/boost_python_builder.py", line 106, in __init__
        , indexing_suite_version)
      File "/usr/local/lib/python3.6/site-packages/pyplusplus/module_builder/boost_python_builder.py", line 149, in __parse_declarations
        decls = reader.read_files( files, compilation_mode )
      File "/usr/local/lib/python3.6/site-packages/pygccxml/parser/project_reader.py", line 264, in read_files
        return self.__parse_file_by_file(files)
      File "/usr/local/lib/python3.6/site-packages/pygccxml/parser/project_reader.py", line 292, in __parse_file_by_file
        decls = reader.read_file(header)
      File "/usr/local/lib/python3.6/site-packages/pygccxml/parser/source_reader.py", line 356, in read_file
        return self.read_cpp_source_file(source_file)
      File "/usr/local/lib/python3.6/site-packages/pygccxml/parser/source_reader.py", line 375, in read_cpp_source_file
        xml_file = self.create_xml_file(ffname)
      File "/usr/local/lib/python3.6/site-packages/pygccxml/parser/source_reader.py", line 324, in create_xml_file
        ": %s status:%s" % (gccxml_msg, exit_status))
    RuntimeError: Error occurred while running CASTXML:  status:1

然后我尝试做一个eendian.h

的软链接
ln -s /usr/include/machine/endian.h /usr/local/include/endian.h

我得到了以下错误:

    INFO Parsing source file "Bonjour.hpp" ...
    In file included from Bonjour.hpp:1:
    In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/string:469:
    In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/__config:235:
    /usr/local/include/endian.h:37:2: error: architecture not supported
    #error architecture not supported
     ^
    In file included from Bonjour.hpp:1:
    In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/string:469:
    /Library/Developer/CommandLineTools/usr/include/c++/v1/__config:906:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or
          '-fms-extensions' to enable support for __declspec attributes
    _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container(
    ^
    /Library/Developer/CommandLineTools/usr/include/c++/v1/__config:583:37: note: expanded from macro '_LIBCPP_FUNC_VIS'
    #define _LIBCPP_FUNC_VIS            _LIBCPP_DLL_VIS
                                        ^
    /Library/Developer/CommandLineTools/usr/include/c++/v1/__config:576:26: note: expanded from macro '_LIBCPP_DLL_VIS'
    # define _LIBCPP_DLL_VIS __declspec(dllimport)
                             ^
    /Library/Developer/CommandLineTools/usr/include/c++/v1/__config:940:4: error: "No thread API"

ps:

ProductName:    Mac OS X
ProductVersion: 10.13.3
BuildVersion:   17D47
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

我想知道为什么会遇到这些错误,似乎我可以用clang 编译。谢谢任何可以回答此问题的人!

i手动在我的Mac上编译Castxml,毫无疑问。在我只用啤酒安装CastXML之前。希望有用!

我不确定是什么让您得出结论std::string的问题。

我可以看到一些有趣的东西:

  • /library/developer/commandlinetools/usr/includs/c /v1/__配置:940:4:错误:"无线程API"

    这可能表明您需要链接线程支持。编译器通常使用-pthread标志,但是您可能还需要在平台上指定链接器输入(而不是?(。在gcc/clang上,链接器输入

  • 通常是-pthread-lpthread
  • /Library/Developer/CommandLineTools/usr/include/c++/v1/__config:906:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or
      '-fms-extensions' to enable support for __declspec attributes
    

    尝试使用-fms-extensions-fdeclspec