当我使用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?
我要生成的代码
#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上,链接器输入
通常是 /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
-pthread
和-lpthread
相关文章:
- 如何在c++17中制作一个模板包装器/装饰器
- std::vector的包装器,使数组的结构看起来像结构的数组
- 如何在c++迭代器类型中包装std::chrono
- 是否可以用"iostream"包装现有的TCP/OOpenSSL会话
- 用pybind11包装C++抽象类时出错
- 为左值和右值的包装器实现C++范围
- C结构,其指针将被包装在unique_ptr中
- 如何包装第三方DLL在R中使用
- 在类型和包装器之间reinterpret_cast是否安全<Type>?
- 将 N-arg 函数包装到另一个函数中
- 元组由 Swig 生成的 Python 包装器返回,用于C++向量
- 包装一个对象并假装它是一个 int
- 使用 Python Extension API 包装复杂C++类
- 外壳包装器句柄/执行交互式命令管道C++ UNIX
- 包装C++类时不完整的类型 GLFWwindow
- 将函数包装器转换为 std::function
- C++函数包装器来捕获某些信号
- 创建包装升压适配器的自定义范围类
- 如何包装(撰写)增强 hana 地图并访问括号运算符(运算符 [])?
- 当我使用py 生成时,然后在macOS上boost.python包装器时,我会发现有关std :: string的错