【问题标题】:c++ linking error : cannot link objects [closed]c ++链接错误:无法链接对象[关闭]
【发布时间】:2012-01-28 22:21:29
【问题描述】:

我正在尝试用 C++ 编译一个程序 标头在 .h 中定义,定义在 cpp 文件中 问题是我得到了链接错误

layer.obj : error LNK2005: "public: __thiscall input_layer::input_layer(int,int)" (??0input_layer@@QAE@HH@Z) already defined in kohonen.obj
layer.obj : error LNK2005: "public: __thiscall input_layer::~input_layer(void)" (??1input_layer@@QAE@XZ) already defined in kohonen.obj
layer.obj : error LNK2005: "public: virtual void __thiscall input_layer::calc_out(void)" (?calc_out@input_layer@@UAEXXZ) already defined in kohonen.obj
layer.obj : error LNK2005: "public: __thiscall output_layer::output_layer(int,int)" (??0output_layer@@QAE@HH@Z) already defined in kohonen.obj
layer.obj : error LNK2005: "public: __thiscall output_layer::~output_layer(void)" (??1output_layer@@QAE@XZ) already defined in kohonen.obj
layer.obj : error LNK2005: "public: virtual void __thiscall output_layer::calc_out(void)" (?calc_out@output_layer@@UAEXXZ) already defined in kohonen.obj
layer.obj : error LNK2005: "public: void __thiscall output_layer::calc_error(float &)" (?calc_error@output_layer@@QAEXAAM@Z) already defined in kohonen.obj
layer.obj : error LNK2005: "public: void __thiscall output_layer::randomize_weights(void)" (?randomize_weights@output_layer@@QAEXXZ) already defined in kohonen.obj
layer.obj : error LNK2005: "public: void __thiscall output_layer::update_weights(float)" (?update_weights@output_layer@@QAEXM@Z) already defined in kohonen.obj
layer.obj : error LNK2005: "public: void __thiscall output_layer::list_weights(void)" (?list_weights@output_layer@@QAEXXZ) already defined in kohonen.obj
layer.obj : error LNK2005: "public: void __thiscall output_layer::list_errors(void)" (?list_errors@output_layer@@QAEXXZ) already defined in kohonen.obj
layer.obj : error LNK2005: "public: void __thiscall output_layer::write_weights(int,struct _iobuf *)" (?write_weights@output_layer@@QAEXHPAU_iobuf@@@Z) already defined in kohonen.obj
layer.obj : error LNK2005: "public: void __thiscall output_layer::read_weights(int,struct _iobuf *)" (?read_weights@output_layer@@QAEXHPAU_iobuf@@@Z) already defined in kohonen.obj
layer.obj : error LNK2005: "public: void __thiscall output_layer::list_outputs(void)" (?list_outputs@output_layer@@QAEXXZ) already defined in kohonen.obj
layer.obj : error LNK2005: "public: __thiscall middle_layer::middle_layer(int,int)" (??0middle_layer@@QAE@HH@Z) already defined in kohonen.obj
layer.obj : error LNK2005: "public: __thiscall middle_layer::~middle_layer(void)" (??1middle_layer@@QAE@XZ) already defined in kohonen.obj
layer.obj : error LNK2005: "public: void __thiscall middle_layer::calc_error(void)" (?calc_error@middle_layer@@QAEXXZ) already defined in kohonen.obj
layer.obj : error LNK2005: "public: __thiscall network::network(void)" (??0network@@QAE@XZ) already defined in kohonen.obj
layer.obj : error LNK2005: "public: __thiscall network::~network(void)" (??1network@@QAE@XZ) already defined in kohonen.obj
layer.obj : error LNK2005: "public: void __thiscall network::set_training(unsigned int const &)" (?set_training@network@@QAEXABI@Z) already defined in kohonen.obj
layer.obj : error LNK2005: "public: unsigned int __thiscall network::get_training_value(void)" (?get_training_value@network@@QAEIXZ) already defined in kohonen.obj
layer.obj : error LNK2005: "public: void __thiscall network::get_layer_info(void)" (?get_layer_info@network@@QAEXXZ) already defined in kohonen.obj
layer.obj : error LNK2005: "public: void __thiscall network::set_up_network(void)" (?set_up_network@network@@QAEXXZ) already defined in kohonen.obj
layer.obj : error LNK2005: "public: void __thiscall network::randomize_weights(void)" (?randomize_weights@network@@QAEXXZ) already defined in kohonen.obj
layer.obj : error LNK2005: "public: void __thiscall network::update_weights(float)" (?update_weights@network@@QAEXM@Z) already defined in kohonen.obj
layer.obj : error LNK2005: "public: void __thiscall network::write_weights(struct _iobuf *)" (?write_weights@network@@QAEXPAU_iobuf@@@Z) already defined in kohonen.obj
layer.obj : error LNK2005: "public: void __thiscall network::read_weights(struct _iobuf *)" (?read_weights@network@@QAEXPAU_iobuf@@@Z) already defined in kohonen.obj
layer.obj : error LNK2005: "public: void __thiscall network::list_weights(void)" (?list_weights@network@@QAEXXZ) already defined in kohonen.obj
layer.obj : error LNK2005: "public: void __thiscall network::list_outputs(void)" (?list_outputs@network@@QAEXXZ) already defined in kohonen.obj
layer.obj : error LNK2005: "public: void __thiscall network::write_outputs(struct _iobuf *)" (?write_outputs@network@@QAEXPAU_iobuf@@@Z) already defined in kohonen.obj
layer.obj : error LNK2005: "public: void __thiscall network::list_errors(void)" (?list_errors@network@@QAEXXZ) already defined in kohonen.obj
layer.obj : error LNK2005: "public: int __thiscall network::fill_IObuffer(struct _iobuf *)" (?fill_IObuffer@network@@QAEHPAU_iobuf@@@Z) already defined in kohonen.obj
layer.obj : error LNK2005: "public: void __thiscall network::set_up_pattern(int)" (?set_up_pattern@network@@QAEXH@Z) already defined in kohonen.obj
layer.obj : error LNK2005: "public: void __thiscall network::forward_prop(void)" (?forward_prop@network@@QAEXXZ) already defined in kohonen.obj
layer.obj : error LNK2005: "public: void __thiscall network::backward_prop(float &)" (?backward_prop@network@@QAEXAAM@Z) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: __thiscall Kohonen_layer::Kohonen_layer(int,int,int)" (??0Kohonen_layer@@QAE@HHH@Z) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: __thiscall Kohonen_layer::~Kohonen_layer(void)" (??1Kohonen_layer@@QAE@XZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: virtual void __thiscall Kohonen_layer::calc_out(void)" (?calc_out@Kohonen_layer@@UAEXXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall Kohonen_layer::randomize_weights(void)" (?randomize_weights@Kohonen_layer@@QAEXXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall Kohonen_layer::update_neigh_size(int)" (?update_neigh_size@Kohonen_layer@@QAEXH@Z) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall Kohonen_layer::update_weights(float)" (?update_weights@Kohonen_layer@@QAEXM@Z) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall Kohonen_layer::list_weights(void)" (?list_weights@Kohonen_layer@@QAEXXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall Kohonen_layer::list_outputs(void)" (?list_outputs@Kohonen_layer@@QAEXXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: float __thiscall Kohonen_layer::get_win_dist(void)" (?get_win_dist@Kohonen_layer@@QAEMXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: __thiscall Kohonen_network::Kohonen_network(void)" (??0Kohonen_network@@QAE@XZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: __thiscall Kohonen_network::~Kohonen_network(void)" (??1Kohonen_network@@QAE@XZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall Kohonen_network::get_layer_info(void)" (?get_layer_info@Kohonen_network@@QAEXXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall Kohonen_network::set_up_network(int)" (?set_up_network@Kohonen_network@@QAEXH@Z) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall Kohonen_network::randomize_weights(void)" (?randomize_weights@Kohonen_network@@QAEXXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall Kohonen_network::update_neigh_size(int)" (?update_neigh_size@Kohonen_network@@QAEXH@Z) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall Kohonen_network::update_weights(float)" (?update_weights@Kohonen_network@@QAEXM@Z) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall Kohonen_network::list_weights(void)" (?list_weights@Kohonen_network@@QAEXXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall Kohonen_network::list_outputs(void)" (?list_outputs@Kohonen_network@@QAEXXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall Kohonen_network::get_next_vector(struct _iobuf *)" (?get_next_vector@Kohonen_network@@QAEXPAU_iobuf@@@Z) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall Kohonen_network::process_next_pattern(void)" (?process_next_pattern@Kohonen_network@@QAEXXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: float __thiscall Kohonen_network::get_win_dist(void)" (?get_win_dist@Kohonen_network@@QAEMXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: int __thiscall Kohonen_network::get_win_index(void)" (?get_win_index@Kohonen_network@@QAEHXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: __thiscall input_layer::input_layer(int,int)" (??0input_layer@@QAE@HH@Z) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: __thiscall input_layer::~input_layer(void)" (??1input_layer@@QAE@XZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: virtual void __thiscall input_layer::calc_out(void)" (?calc_out@input_layer@@UAEXXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: __thiscall output_layer::output_layer(int,int)" (??0output_layer@@QAE@HH@Z) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: __thiscall output_layer::~output_layer(void)" (??1output_layer@@QAE@XZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: virtual void __thiscall output_layer::calc_out(void)" (?calc_out@output_layer@@UAEXXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall output_layer::calc_error(float &)" (?calc_error@output_layer@@QAEXAAM@Z) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall output_layer::randomize_weights(void)" (?randomize_weights@output_layer@@QAEXXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall output_layer::update_weights(float)" (?update_weights@output_layer@@QAEXM@Z) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall output_layer::list_weights(void)" (?list_weights@output_layer@@QAEXXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall output_layer::list_errors(void)" (?list_errors@output_layer@@QAEXXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall output_layer::write_weights(int,struct _iobuf *)" (?write_weights@output_layer@@QAEXHPAU_iobuf@@@Z) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall output_layer::read_weights(int,struct _iobuf *)" (?read_weights@output_layer@@QAEXHPAU_iobuf@@@Z) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall output_layer::list_outputs(void)" (?list_outputs@output_layer@@QAEXXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: __thiscall middle_layer::middle_layer(int,int)" (??0middle_layer@@QAE@HH@Z) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: __thiscall middle_layer::~middle_layer(void)" (??1middle_layer@@QAE@XZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall middle_layer::calc_error(void)" (?calc_error@middle_layer@@QAEXXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: __thiscall network::network(void)" (??0network@@QAE@XZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: __thiscall network::~network(void)" (??1network@@QAE@XZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall network::set_training(unsigned int const &)" (?set_training@network@@QAEXABI@Z) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: unsigned int __thiscall network::get_training_value(void)" (?get_training_value@network@@QAEIXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall network::get_layer_info(void)" (?get_layer_info@network@@QAEXXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall network::set_up_network(void)" (?set_up_network@network@@QAEXXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall network::randomize_weights(void)" (?randomize_weights@network@@QAEXXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall network::update_weights(float)" (?update_weights@network@@QAEXM@Z) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall network::write_weights(struct _iobuf *)" (?write_weights@network@@QAEXPAU_iobuf@@@Z) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall network::read_weights(struct _iobuf *)" (?read_weights@network@@QAEXPAU_iobuf@@@Z) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall network::list_weights(void)" (?list_weights@network@@QAEXXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall network::list_outputs(void)" (?list_outputs@network@@QAEXXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall network::write_outputs(struct _iobuf *)" (?write_outputs@network@@QAEXPAU_iobuf@@@Z) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall network::list_errors(void)" (?list_errors@network@@QAEXXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: int __thiscall network::fill_IObuffer(struct _iobuf *)" (?fill_IObuffer@network@@QAEHPAU_iobuf@@@Z) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall network::set_up_pattern(int)" (?set_up_pattern@network@@QAEXH@Z) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall network::forward_prop(void)" (?forward_prop@network@@QAEXXZ) already defined in kohonen.obj
layerk.obj : error LNK2005: "public: void __thiscall network::backward_prop(float &)" (?backward_prop@network@@QAEXAAM@Z) already defined in kohonen.obj
Debug/Test4.exe : fatal error LNK1169: one or more multiply defined symbols found

程序的代码源可以在这里下载 http://blog.drsofts.com/konohen.zip

【问题讨论】:

  • 您应该重新表述您的问题。在这种形式下,它可能会被关闭。没有人会下载和检查您的程序。 需要一些合作
  • 看起来您要么链接同一个目标文件两次,要么通过弄乱#includes 等方式定义相同的函数两次。尝试链接详细输出并从中获取更多信息。尝试从项目中删除 kohonen.cpp。然后解释你尝试了什么以及结果是什么。

标签: c++ linker


【解决方案1】:

不看你的代码,只看错误,你似乎做了以下事情之一:

  1. 在标头中实现了一些函数,但在类定义之外没有将函数标记为内联
  2. 实现的函数在不同的目标文件中相乘
  3. 包含 .cpp 文件而不是头文件

我个人猜测是第三种情况:检查 kohonen.cpp 和 layerk.cpp 是否存在此问题。它也可能在这些文件中包含的标题之一中。您可以使用 -E 或 /E 编译器选项来获取预处理文件的结果:这可能有助于找到函数定义的锥体。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-22
    • 1970-01-01
    • 1970-01-01
    • 2014-11-17
    相关资源
    最近更新 更多