xcode链接器在调试模式下错误(重复符号)
xcode linker error in Debug mode (duplicate symbol)
我在使用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没有给我任何问题。但是当我尝试在xcode中编译Debug
模式时,我得到以下错误:Apple Mach-O link (old) error
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)
发布模式也没有问题
通过试错,我找到了解决这个问题的方法。我需要将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;
但我不明白为什么它工作。有人能给我解释一下有什么不同吗?
相关文章:
- 在C++中使用内联方法时出现未定义的符号错误
- 当 lib 已添加到其他依赖项时,如何在 VS 中调试未解析的外部符号错误
- 函数指针给我"重新声明为不同类型的符号"错误
- "byte":使用Crypto++和Windows SDK时出现不明确的符号错误
- 函数路径追加上未解决的外部符号错误
- 作为成员的静态类模板实例会导致未解析的外部符号错误
- C++ XCODE ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -
- 共享库中使用"使用命名空间"定义的符号错误
- 在FreesWitch中使用AWS C SDK加载模块时未定义的符号错误
- 在 Mac 上C++编译代码时处理“dyld:惰性符号绑定失败:找不到符号”错误
- C++编译错误LNK2019:未解决的外部符号错误
- VTK / ITK/ QT - 未解决的外部符号错误 (LNK2001)
- QT创建者:简单程序未解决的外部符号和外部符号错误
- C++编译错误:ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v
- 标准::字符串::空的未定义符号错误;Mac OS High Sierra 上的 c++ 标准方法链接错误
- ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- 由于使用未签名的INT,因此在Variadic模板C 上未解决的外部符号错误
- OSX MOJAVE -LD:架构X86_64 clang找不到符号:错误:链接器命令失败,出口代码1
- 使用从WINRT网格类派生的抽象类时,Casttobase未解决的外部符号错误
- LD:架构x86_64 clang找不到符号:错误:链接器命令失败,出口代码1(使用-v to See