首页 > 解决方案 > 如何编译和运行使用 fltk 的程序?

问题描述

我有一个简单的小程序(命名为 hello_fltk.cpp),(我使用 Ubuntu),我附在下面:

#include <FL/Fl.H>            
<FL/Fl_Window.H>     
#include <FL/Fl_Box.H>        

#include <string>

int main(int argc, char **argv) {
  const std::string hw_s = "Hello, World!";
  Fl_Window *window = new Fl_Window(340, 180);                 
  Fl_Box *box = new Fl_Box(20, 40, 300, 100, hw_s.c_str());  

  box->box(FL_UP_BOX);                 
  box->labelfont(FL_BOLD + FL_ITALIC);  
  box->labelsize(36);                  
  box->labeltype(FL_SHADOW_LABEL);      

  window->end();               
  window->show(argc, argv);      
  Fl::run();                    
  return 0;
}

好的,现在当我编译它时,我在终端上写:g++ hello_fltk.cpp。我发现的错误是

/tmp/ccfyku2b.o:在函数“main”中:
hello_fltk.cpp:(.text+0x70): 未定义引用`Fl_Window::Fl_Window(int, int, char const*)'
hello_fltk.cpp:(.text+0xb0): 未定义引用 `Fl_Box::Fl_Box(int, int, int, int, char const*)'
hello_fltk.cpp:(.text+0xf0): 对“fl_define_FL_SHADOW_LABEL()”的未定义引用
hello_fltk.cpp:(.text+0x106): 对“Fl_Group::end()”的未定义引用
hello_fltk.cpp:(.text+0x11b): 未定义引用`Fl_Window::show(int, char**)'
hello_fltk.cpp:(.text+0x120): 对“Fl::run()”的未定义引用
collect2:错误:ld 返回 1 个退出状态

所以有未定义的引用,但是我正确安装了所有报告为未找到的功能,所以也许我编译错误。谁能帮我解决这个链接器错误?提前致谢!

标签: c++fltk

解决方案


推荐阅读