2

I'm currently learning c++ with the book Programming: Principles and Practice Using C++ from Stroustrup and am in chapter 12. I'm now trying since days to get FLTK with the specific headers working.

I have installed FLTK with MacPorts. When i'm trying to compile the code including Simple_window.h, i get the following errors:

bash-3.2# fltk-config --compile main.cpp

/usr/bin/g++-4.2 -arch i386 -I/opt/local/include -pipe -arch i386 -arch i386 
-D_THREAD_SAFE -D_REENTRANT -o main main.cpp -arch i386 -arch i386
 /opt/local/lib/libfltk.a -lpthread -framework Carbon -framework 
ApplicationServices 

Undefined symbols:
  "vtable for Graph_lib::Window", referenced from:
      __ZTVN9Graph_lib6WindowE$non_lazy_ptr in cc1oxcSA.o
     (maybe you meant: __ZTVN9Graph_lib6WindowE$non_lazy_ptr)
  "vtable for Graph_lib::Button", referenced from:
      __ZTVN9Graph_lib6ButtonE$non_lazy_ptr in cc1oxcSA.o
 (maybe you meant: __ZTVN9Graph_lib6ButtonE$non_lazy_ptr)
  "Simple_window::Simple_window(Point, int, int, String const&)", referenced from:
  _main in cc1oxcSA.o
  "Graph_lib::Window::draw()", referenced from:
  vtable for Simple_windowin cc1oxcSA.o
  "typeinfo for Graph_lib::Window", referenced from:
  typeinfo for Simple_windowin cc1oxcSA.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

I have no idea what this means. I read the answers here (SO). I created the .o files. I'm trying to compile this on Mac OS with fltk-config.

Community
  • 1
  • 1
MCPP
  • 49
  • 2
  • 6
  • You are not linking correctly and forget the object files? You need to include them on the commandline. – pmr Dec 31 '11 at 13:40
  • @pmr Possible, but i'm an beginner, so how do i include them? – MCPP Dec 31 '11 at 13:48

3 Answers3

2

It seems to me that there should be a -l (dash ell) in front of /opt/local/lib/libfltk.a when you invoke the compiler. Or you could replace /opt/local/lib/libfltk.a with -L/opt/local/lib -lfltk which might be more conventional.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
1

I got the FLTK program '12.3 A first example' working on Linux using the following steps:

then unzip it and go to the Programming-code/GUI folder.

  • In that folder, add #include <cstdlib> to the file std_lib_facilities.h to avoid an atoi not declared error in the next step
  • Run make at the command line in the Programming-code/GUI folder. This should create the file libbookgui.a.
  • Assuming the program is named Example.cpp, run the following command:

    gcc `fltk-config --use-forms --use-gl --use-images --ldflags`Example.cpp libbookgui.a

  • Run the a.out executable

0

Using a sample program from source code found in a PDF FLTK-Tutorial.pdf

I had to add the following lines to get a clean compile in my Ubuntu Linux.

// 3 includes just below are not in the example but are required
// for a clean compile
#include <Fl/x.H>
#include <stdlib.h>
#include <stdio.h>

You must configure your compile line correctly. FLTK has fltk-config tool to help with the configuration.

fltk-config
to get the help message for fltk-config. Read the output to determine what you need to put in for the compile, the link, and any of the compatibility (gl, glut, forms, etc.) for packages you are using.

Copy this information into your compile command.

You can also use the --compile prgrname.cxx switch to compile directly. Include -g because you will want gdb support.

For example:

fltk-config --cxxflags --ldflags

Gives (for me):

-I/usr/include/freetype2 -g -O2 -D_THREAD_SAFE -D_REENTRANT -Wl,-Bsymbolic-functions -lfltk

Add an output name and the input programs:

gcc -I/usr/include/freetype2 -g -O2 -D_THREAD_SAFE -D_REENTRANT -Wl,-Bsymbolic-functions -lfltk mousedrawtest.cpp mousedraw.cpp -o b.out

While there is less to learn for FLTK, it is not for the faint of heart. Erco's (Greg Ercolano) tutorials are excellent and sample code for many common challenges. http://seriss.com/people/erco/fltk/

http://www.fltk.org/documentation.php/doc-1.1/basics.html

There are a number of other good ones search: FLTK tutorial

When converting from simple sample programs to a real object oriented model, keep in mind scope, particularly for the top level window and its contents.

Today, Wednesday, I know much more about gdb, scope, and namespace than I did on Monday.

Nunser
  • 4,512
  • 8
  • 25
  • 37
cbcalvin
  • 11
  • 1