我遇到了使用boost :: error_info编译一段代码的问题。我有一个包含错误代码errors.h
#ifndef ERRORS_H
#define ERRORS_H
#include <boost/exception/all.hpp>
#include <string>
enum error_num {
ERR_IS_NOT_ZERO,
ERR_IS_ZERO
};
typedef boost::error_info<struct tag_errno_code,error_num> errno_code;
typedef boost::error_info<struct tag_code_line,int> code_line;
typedef boost::error_info<struct tag_err_description,std::string> err_description;
struct exception_base: virtual std::exception, virtual boost::exception { };
struct integral_error: virtual exception_base { };
struct geometry_error: virtual exception_base { };
std::string error_to_str(error_num err);
#endif /* ERRORS_H */
gcc没有给我任何问题。但是当我尝试在Debug
模式下编译xcode时,我收到以下错误:Apple Mach-O Linker(ld)错误
duplicate symbol __ZTSP13tag_code_line in:
....
duplicate symbol __ZTSP19tag_err_description in:
....
duplicate symbol __ZTSP13tag_code_line in:
....
....
ld: 6 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
发布模式没有问题。
答案 0 :(得分:2)
通过试验错误我已经想出如何解决这个问题。我需要将struct tag_...
带出boost::error_info
模板参数:
struct tag_errno_code { };
struct tag_code_line { };
struct tag_err_description { };
typedef boost::error_info<tag_errno_code,error_num> errno_code;
typedef boost::error_info<tag_code_line,int> code_line;
typedef boost::error_info<tag_err_description,std::string> err_description;
但我不明白为什么会这样。有人可以向我解释一下这里有什么区别吗?