gtkmm链接器错误
gtkmm linker error
你好,stackoverflow:),我正在编译一个基本的gui程序,它取2个双的和并打印出来。我的代码实际上很简单,我将首先发布我通过命令行编译的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();
}
我已经做了一个只有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;
}
c++版本有效,所以我需要帮助。如何使链接器工作?
在examplewindow.cc文件中,您正在从examplewindow类中定义std::string double_to_ustring(double a)
。您需要像类的其他成员方法一样对其进行限定:std::string ExampleWindow::double_to_ustring(double a)
相关文章:
- Netbeans 10:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- CMake 错误:链接器命令失败,退出代码为 1 和 cpp.o 文件
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- 如何修复 clang: 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- Android NDK.Build命令失败.未定义的引用.clang++:错误:链接器命令失败,退出代码为1
- 使用cmake错误链接boost日志
- 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用):在 Macbook 上
- C++ XCODE ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -
- clang:错误:链接器命令失败,C++代码中的退出代码为 1(使用 -v 查看调用)
- 静态库中的 g++ 错误链接函数
- 未定义的参考错误链接天然函数Android
- C++编译错误:ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v
- QT Q_PROPERTY错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- OSX MOJAVE -LD:架构X86_64 clang找不到符号:错误:链接器命令失败,出口代码1
- C 错误链接器命令失败了出口代码1(使用-V查看调用)
- LD:架构x86_64 clang找不到符号:错误:链接器命令失败,出口代码1(使用-v to See
- 聚输出错误 - 链接列表
- Xcode链接器错误:链接器命令失败,退出代码为1(使用-v查看调用)
- 尝试构建C DLIB示例无法与数百个未定义的参考错误链接