0

I want to use FLTK to make a GUI. So I installed it on my Mac by brewing it. That worked fine so far.

Nevertheless, when I try to compile a small program, I get this error message:

-------------- 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))

Here is my code:

#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());
}

Believe me, I searched for more than four hours, tried it with a differente IDE (Atom) and so on and so forth. "Normal" C++ is working properly...

Thanks in advance. I appreciate every tip or help I can get :)

Liam Potter
  • 1,732
  • 8
  • 24
  • 47
MagJ_
  • 1
  • 1
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Mike Kinghan Oct 03 '18 at 14:40

2 Answers2

1

You should link compiler to fltk. Go to project->build options->linker options->add and write fltk then save and rebuild the project and run it.

In some usage, you need to link fltk_forms, fltk_gl fltk_images to compiler too.

Amir Fo
  • 5,163
  • 1
  • 43
  • 51
0

The compiler is telling you that it can not find the function definitions for the FLTK functions you are calling. This means that you are not linking the FLTK library correctly. Refer to the instructions on how to link the library here under the heading: Compiling Your Program

Liam Potter
  • 1,732
  • 8
  • 24
  • 47
  • Thanks for your answer but to be honest, I don't get it done either. I got to add this (c++ -I/usr/local/include ...) to a Compiler Line, but where do I find it in Code::Blocks and I think I have to replace the three dots, uhm, what do I have to put there? I'm sorry – MagJ_ Jun 02 '18 at 21:48