首页 > 解决方案 > 代码块的 FLTK 错误

问题描述

我想用 FLTK 做一个 GUI。所以我通过酿造将它安装在我的Mac上。到目前为止效果很好。

然而,当我尝试编译一个小程序时,我收到以下错误消息:

-------------- Build: Debug in fltk_test (compiler: GNU GCC Compiler)---------------

g++  -o bin/Debug/fltk_test obj/Debug/main.o    
Undefined symbols for architecture x86_64:
  "fl_define_FL_SHADOW_LABEL()", referenced from:
      _main in main.o
  "Fl::run()", referenced from:
      _main in main.o
  "Fl_Box::Fl_Box(int, int, int, int, char const*)", referenced from:
      _main in main.o
  "Fl_Group::end()", referenced from:
      _main in main.o
  "Fl_Window::show(int, char**)", referenced from:
      _main in main.o
  "Fl_Window::Fl_Window(int, int, char const*)", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Process terminated with status 1 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))

这是我的代码:

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

int main (int argc, char ** argv)
{
  Fl_Window *window;
  Fl_Box *box;

  window = new Fl_Window (300, 180);
  box = new Fl_Box (20, 40, 260, 100, "Hello World!");

  box->box (FL_UP_BOX);
  box->labelsize (36);
  box->labelfont (FL_BOLD+FL_ITALIC);
  box->labeltype (FL_SHADOW_LABEL);
  window->end ();
  window->show (argc, argv);

  return(Fl::run());
}

相信我,我搜索了四个多小时,尝试了不同的 IDE(Atom)等等。“正常” C++ 工作正常...

提前致谢。我感谢我能得到的每一个提示或帮助:)

标签: c++macosfltk

解决方案


您应该将编译器链接到 fltk。去project->build options->linker options->addfltk然后保存并重建项目并运行它。

在某些用法中,您也需要将 , 链接fltk_formsfltk_gl fltk_images编译器。


推荐阅读