c ++链接错误:无法链接对象

时间:2012-01-28 22:21:30

标签: c++ linker

我正在尝试用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

1 个答案:

答案 0 :(得分:4)

在没有查看代码的情况下,只有错误,您似乎已经完成了以下任一操作:

  1. 在标题中实现了一些函数,但在类定义之外,没有标记函数inline
  2. 实现的函数在不同的目标文件中相乘
  3. 包含.cpp文件而不是头文件
  4. 我个人猜测第三种情况是:检查kohonen.cpp和layerk.cpp是否存在此问题。它也可能位于这些文件中包含的标题之一中。您可以使用-E或/ E编译器选项来获取预处理文件的结果:这可能有助于找到函数定义的位置。