C++ gtkmm链接器错误

C++ gtkmm链接器错误,c++,gcc,linker,g++,gtkmm,C++,Gcc,Linker,G++,Gtkmm,您好stackoverflow:), 我正在编译一个基本的gui程序,它取两个双倍的和并打印出来。我的代码实际上非常简单,我将首先发布我用命令行编译的3个文件 "g++ main.cc examplewindow.cc -o main `pkg-config gtkmm-3.0 --cflags --libs`" 命令行上的错误是: /tmp/ccSeXudb.o: In function `ExampleWindow::on_button_clicked_calculate()': exam

您好stackoverflow:), 我正在编译一个基本的gui程序,它取两个双倍的和并打印出来。我的代码实际上非常简单,我将首先发布我用命令行编译的3个文件

"g++ main.cc examplewindow.cc -o main `pkg-config gtkmm-3.0 --cflags --libs`"
命令行上的错误是:

/tmp/ccSeXudb.o: In function `ExampleWindow::on_button_clicked_calculate()': examplewindow.cc:(.text+0x1e70): undefined reference to `ExampleWindow::double_to_ustring(double)'

collect2: error: ld returned 1 exit status
这是3个文件:

                                    examplewindow.h

#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>
#include <boost/lexical_cast.hpp>
#include <stdlib.h>
#include <string>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  void on_checkbox_editable_toggled();
  void on_checkbox_visibility_toggled();
  Glib::ustring get_entry1();
  Glib::ustring get_entry2();
  std::string double_to_ustring(double a);
  void on_button_clicked_calculate();
  void on_button_close();

  //Child widgets:
  //Gtk::Box m_HBox;
  Gtk::Box m_VBox;
  Gtk::Box m_ZBox;
  Gtk::Entry m_Entry, m_Entry2, m_Entry3; 
  Gtk::Button m_Button_Close, m_Button_Calculate;
  //Gtk::CheckButton m_CheckButton_Editable, m_CheckButton_Visible;
  Gtk::Label m_Label_Sum, m_Label_Equals;
};

#endif //GTKMM_EXAMPLEWINDOW_H





                                     main.cc

#include "examplewindow.h"
#include <gtkmm/application.h>

int main(int argc, char *argv[])
{
  Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv,     "org.gtkmm.example");

  ExampleWindow window;

  //Shows the window and returns when it is closed.
  return app->run(window);
}




                                  examplewindow.cc

#include "examplewindow.h"
#include <iostream>
#include <boost/lexical_cast.hpp>
#include <stdlib.h>
#include <string>


ExampleWindow::ExampleWindow()
: m_VBox(Gtk::ORIENTATION_VERTICAL),
  m_ZBox(Gtk::ORIENTATION_HORIZONTAL),
  m_Button_Calculate("Calculate"),
  m_Button_Close("Close")
{
  set_size_request(200, 100);
  set_title("Trial Version:P");

  add(m_VBox);


  m_VBox.add(m_ZBox);

  m_Entry.set_max_length(50);
  m_Entry.set_text("First");
  m_Entry.set_text(m_Entry.get_text() + " value");
  m_Entry.select_region(0, m_Entry.get_text_length());
  m_ZBox.pack_start(m_Entry);

  m_Label_Sum.set_text("+");
  m_ZBox.pack_start(m_Label_Sum); 

  m_Entry2.set_max_length(50);
  m_Entry2.set_text("Second");
  m_Entry2.set_text(m_Entry2.get_text() + " value");
  m_Entry2.select_region(0, m_Entry2.get_text_length());
  m_ZBox.pack_start(m_Entry2);

  m_Label_Equals.set_text("=");
  m_ZBox.pack_start(m_Label_Equals);

  m_Entry3.set_max_length(50);
  m_Entry3.set_text("The");
  m_Entry3.set_text(m_Entry3.get_text() + " result"); 
  m_Entry3.set_editable(0); 
  m_Entry3.select_region(0, m_Entry3.get_text_length());
  m_ZBox.pack_start(m_Entry3);


  m_Button_Calculate.signal_clicked().connect( sigc::mem_fun(*this,     &ExampleWindow::on_button_clicked_calculate) );
  m_VBox.pack_start(m_Button_Calculate);
  m_Button_Calculate.set_can_default();
  m_Button_Calculate.grab_default();
  m_Button_Close.signal_clicked().connect( sigc::mem_fun(*this,
              &ExampleWindow::on_button_close) );
  m_VBox.pack_start(m_Button_Close);
  m_Button_Close.set_can_default();
  m_Button_Close.grab_default();

  show_all_children();
}

ExampleWindow::~ExampleWindow()
{
}

Glib::ustring ExampleWindow::get_entry1()
{
  return m_Entry.get_text();
}

Glib::ustring ExampleWindow::get_entry2()
{
  return m_Entry2.get_text();
}
std::string double_to_ustring(double a)
{
  std::string str = boost::lexical_cast<std::string>(a);
  return str; 
}

void ExampleWindow::on_button_clicked_calculate()
{ 
  Glib::ustring a = get_entry1();
  Glib::ustring b = get_entry2();
  double m = std::atof( a.c_str() ) + std::atof( b.c_str() );
  Glib::ustring z = double_to_ustring(m);
  m_Entry3.set_text(z);
}

void ExampleWindow::on_button_close()
{
  hide();

}
examplewindow.h
#ifndef GTKMM\u示例窗口
#定义GTKMM_示例窗口
#包括
#包括
#包括
#包括
类示例窗口:公共Gtk::窗口
{
公众:
示例窗口();
虚拟~ExampleWindow();
受保护的:
//信号处理程序:
在复选框上无效\u可编辑\u切换();
在复选框上无效\u可见性\u切换();
Glib::ustring get_entry1();
Glib::ustring get_entry2();
std::字符串双精度到双精度(双a);
在按钮上无效\u单击\u计算();
按钮关闭时无效();
//子窗口小部件:
//Gtk::盒子m_HBox;
Gtk::Box m_VBox;
Gtk::盒子Mzbox;
Gtk::条目m_条目、m_条目2、m_条目3;
Gtk::按钮m_按钮关闭,m_按钮计算;
//Gtk::CheckButton m_CheckButton_可编辑,m_CheckButton_可见;
Gtk::Label m_Label_Sum,m_Label_等于;
};
#endif//GTKMM\u示例窗口
main.cc
#包括“examplewindow.h”
#包括
int main(int argc,char*argv[])
{
Glib::RefPtr app=Gtk::Application::create(argc,argv,“org.gtkmm.example”);
例如窗户;
//显示窗口并在关闭时返回。
返回应用程序->运行(窗口);
}
examplewindow.cc
#包括“examplewindow.h”
#包括
#包括
#包括
#包括
ExampleWindow::ExampleWindow()
:m_VBox(Gtk::方向_垂直),
m_ZBox(Gtk::方向_水平),
m_按钮_计算(“计算”),
m_按钮_关闭(“关闭”)
{
设置大小请求(200100);
设置标题(“试用版:P”);
添加(m_VBox);
m_VBox.add(m_ZBox);
m_条目。设置最大长度(50);
m_条目。设置_文本(“第一”);
m_Entry.set_text(m_Entry.get_text()+“value”);
m_条目。选择_区域(0,m_条目。获取_文本_长度());
m_ZBox.pack_start(m_条目);
m_Label_Sum.set_text(“+”);
m_ZBox.pack_start(m_Label_Sum);
m_入口2.设置最大长度(50);
m_Entry2.设置文本(“第二”);
m_Entry2.set_text(m_Entry2.get_text()+“value”);
m_Entry2.选择_区域(0,m_Entry2.get_text_length());
m_ZBox.pack_start(m_Entry2);
m_Label_等于。设置_文本(“=”);
m_ZBox.pack_start(m_Label_等于);
入口3.设置最大长度(50);
m_Entry3.设置文本(“The”);
m_Entry3.set_text(m_Entry3.get_text()+“result”);
m_Entry3.设置_可编辑(0);
m_Entry3.选择_区域(0,m_Entry3.get_text_length());
m_ZBox.pack_start(m_Entry3);
m_按钮_计算。信号_单击().connect(sigc::mem_fun(*此,&ExampleWindow::on_按钮_单击_计算));
m_VBox.pack_start(m_按钮\u计算);
m_按钮_计算。设置_可以_默认值();
m_按钮_计算。抓取默认值();
m_按钮关闭。信号单击()。连接(sigc::mem_fun(*此,
&示例窗口::打开按钮(关闭));
m_VBox.打包启动(m_按钮关闭);
m_按钮_关闭。设置_可以_默认值();
m_按钮_关闭。抓取默认值();
显示所有子项();
}
ExampleWindow::~ExampleWindow()
{
}
Glib::ustring ExampleWindow::get\u entry1()
{
返回m_条目。获取m_文本();
}
Glib::ustring ExampleWindow::get\u entry2()
{
返回m_Entry2.get_text();
}
标准::字符串双精度到双精度(双a)
{
std::string str=boost::词法转换(a);
返回str;
}
void ExampleWindow::在按钮上单击了计算()
{ 
Glib::ustring a=get_entry1();
Glib::ustring b=get_entry2();
双m=std::atof(a.c_str())+std::atof(b.c_str());
Glib::ustring z=双对多(m);
m_Entry3.set_text(z);
}
void ExampleWindow::打开按钮关闭()
{
隐藏();
}
<>我做了一个C++版本:

#include <iostream>
#include <boost/lexical_cast.hpp>
#include <stdlib.h>
#include <string>

using namespace std;

string double_to_string(double a)
{
  string str = boost::lexical_cast<std::string>(a);
  return str; 
}

int main()
{
  string a="3", b="5";
  double m = atof( a.c_str() ) + atof( b.c_str() );
  string z = double_to_string(m);
  cout << z << endl;
}
#包括
#包括
#包括
#包括
使用名称空间std;
字符串双_至_字符串(双a)
{
string str=boost::词法转换(a);
返回str;
}
int main()
{
字符串a=“3”,b=“5”;
双m=atof(a.c_str())+atof(b.c_str());
字符串z=双_至_字符串(m);

cout在examplewindow.cc文件中,您正在examplewindow类之外定义
std::string double\u to\u ustring(double a)
。您需要像类的其他成员方法一样限定它:
std::string examplewindow::double\u to\u ustring(double a)