当我在 macOS 上使用 py++ 生成 boost.Python 包装器时,出现关于 std::string 的错误?
Posted
技术标签:
【中文标题】当我在 macOS 上使用 py++ 生成 boost.Python 包装器时,出现关于 std::string 的错误?【英文标题】:When I use py++ to generate then boost.Python wrapper on macOS, I got a error about std::string? 【发布时间】:2018-02-19 06:48:43 【问题描述】:我要为其生成包装器的代码是
#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
然后我尝试做一个endian.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++编译。谢谢任何可以回答这个问题的人!!!
【问题讨论】:
不要用符号链接破解它。你的编译器试图告诉你一些事情。把它涂在上面可能是自找麻烦 【参考方案1】:我在我的mac上手动编译castxml,没有问题了。在我用 brew 安装 castxml 之前。希望有用!
【讨论】:
【参考方案2】:我不确定是什么让您断定std::string
存在问题。
不过,我可以看到一些有趣的事情:
/Library/Developer/CommandLineTools/usr/include/c++/v1/__config: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
【讨论】:
我已经尝试删除 Bonjour.hpp 中的 std::string,没关系 我明白了。但是放大消息并不表明该类型存在实际问题。它提出了值得配置标准库的问题,比如我强调的两点 我通过重新编译 castxml 来解决它,在此之前我用 brew 安装 castxml。 @祈祷酷。考虑将其发布为答案,它可能对其他人有所帮助。更正,我看到你已经这样做了:)干杯。以上是关于当我在 macOS 上使用 py++ 生成 boost.Python 包装器时,出现关于 std::string 的错误?的主要内容,如果未能解决你的问题,请参考以下文章
CFBundleIdentifier在上传使用Electron开发并使用电子构建器构建的macOS应用程序时发生冲突