如何编译和运行使用 fltk 的程序?

时间:2021-03-18 10:44:43

标签: c++ 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: In function `main':
hello_fltk.cpp:(.text+0x70): undefined reference to `Fl_Window::Fl_Window(int, int, char const*)'
hello_fltk.cpp:(.text+0xb0): undefined reference to `Fl_Box::Fl_Box(int, int, int, int, char const*)'
hello_fltk.cpp:(.text+0xf0): undefined reference to `fl_define_FL_SHADOW_LABEL()'
hello_fltk.cpp:(.text+0x106): undefined reference to `Fl_Group::end()'
hello_fltk.cpp:(.text+0x11b): undefined reference to `Fl_Window::show(int, char**)'
hello_fltk.cpp:(.text+0x120): undefined reference to `Fl::run()'
collect2: error: ld returned 1 exit status

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

0 个答案:

没有答案
相关问题