2

In order to try out FLTK, I have the following file structure:

project
|--main.cc
|--include
|  |--FL
|  |  |--all FLTK header files
|--lib
|  |--libfltk.a
|  |--other fltk libraries

With the following content in main.cc:

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

int main()
{
    Fl_Window window(200, 200, "Window title");
    Fl_Box box(0,0,200,200,"Hello, World!");
    window.show();
    return Fl::run();
}

Now when I run:

g++ -std=c++11 -c -o main.o main.cc -I include
g++ -std=c++11 -o main.exe main.o -L lib -lfltk

I get a whole bunch of errors after the second call to g++:

lib/libfltk.a(Fl.o):Fl.cxx:(.text$_ZL13image_to_iconPK12Fl_RGB_Imagebii+0xf3): undefined reference to `CreateDIBSection@24'
lib/libfltk.a(Fl.o):Fl.cxx:(.text$_ZL13image_to_iconPK12Fl_RGB_Imagebii+0x1cf): undefined reference to `DeleteObject@4'
lib/libfltk.a(Fl.o):Fl.cxx:(.text$_ZL13image_to_iconPK12Fl_RGB_Imagebii+0x258): undefined reference to `CreateBitmap@20'
lib/libfltk.a(Fl.o):Fl.cxx:(.text$_ZL13image_to_iconPK12Fl_RGB_Imagebii+0x2a6): undefined reference to `DeleteObject@4'
lib/libfltk.a(Fl.o):Fl.cxx:(.text$_ZL13image_to_iconPK12Fl_RGB_Imagebii+0x2b1): undefined reference to `DeleteObject@4'
lib/libfltk.a(Fl.o):Fl.cxx:(.text$__tcf_1+0x5b): undefined reference to `OleUninitialize@0'
lib/libfltk.a(Fl.o):Fl.cxx:(.text$__tcf_1+0x83): undefined reference to `RestoreDC@8'
etc ...

The result is the same when I try to link the other FLTK libraries. Can anyone help me with that?

I use gcc from Windows, with MingW.

Romain
  • 23
  • 6
  • 1
    There is a handy tool named `fltk-config` included in every FLTK release to help you figure out the libraries and compiler flags to compile FLTK programs. So please run `fltk-config --libs` in a terminal. I guess you have add "-lwindows" or something like this (I don't have windows) – Andy Nov 03 '17 at 07:04

1 Answers1

4

To solve this sort of problems is necessary to take help from fltk-config script. Therefore, it is enought to add line fltk-config --ldflags to compiler to avoid linker errors. Be sure to use "`" symbol around this command since this is the script and its should be executed.

Ans
  • 527
  • 5
  • 9