Author Topic: Linking Libraries  (Read 20645 times)

Offline CaptFalcon33035

  • Single posting newcomer
  • *
  • Posts: 4
Linking Libraries
« on: July 24, 2007, 07:36:52 pm »
I don't know how to link libraries in Code::Blocks correctly.  I've been trying to link the FLTK libraries for quite some time and have been getting the same undefined reference errors throughout.  Long story short, I don't know how to link them correctly, or at least, I assume that is the problem. 

I've placed all of my libraries and FLTK headers in C:\Code-Blocks\Libraries\lib and C:\Code-Blocks\Libraries\include, which currently consist of the lua libraries I haven't touched and FLTK of course.  I opened my project (which currently consists of a "hello world") with Code::Blocks.  This is my code:

Code: [Select]
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>

int main(int argc, char **argv)
  Fl_Window *window = new Fl_Window(600,400);
  window->show(argc, argv);
  return Fl::run();

As you can see, it's very simple.  Now, these are my settings for the Compiler and debugger in Global Compiler Settings:

Code: [Select]
GNU CC Compiler

Nothing in compiler settings tab
Linker settings has every library dealing with FLTK included (by full path name):
    all in the format of C:\Code-Blocks\Libraries\lib\[lib_name]
Search directories for compiler tab:
Search directories for linker tab:
Search directories for resource tab:
Toolchain executables has the default for program files for MinGW installed at C:\MinGW and nothing in additional paths
No custom variables
Other settings:
        Compiler logging: task desc.
        Number of parallel builds: 1
        Max number of errors to log: 50
        No checked options afterward
I'm using the July 21 Nightly build

Now, I keep getting tons of undefined reference errors.
The build messages are as follows:
Code: [Select]
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0x279):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0xc4d):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0xc60):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0xc66):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0xc79):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0xc8d):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0xcfa):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0x1209):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0x12b0):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0x12e1):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0x12f6):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0x130a):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0x23b1):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0x23c5):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0x2811):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0x2843):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0x289a):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0x28d4):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0x2961):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0x296e):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0x2c5f):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0x2c73):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0x2cb2):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0x2cb8):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0x331e):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0x353f):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0x290):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(fl_dnd.o):fl_dnd.cxx:(.text+0x53):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(fl_dnd.o):fl_dnd.cxx:(.text$_ZN12FLDropTarget14QueryInterfaceERK5_GUIDPPv+0x13):: undefined reference to `IID_IUnknown'
C:\Code-Blocks\Libraries\lib\libfltk.a(fl_dnd.o):fl_dnd.cxx:(.text$_ZN12FLDropTarget14QueryInterfaceERK5_GUIDPPv+0x27):: undefined reference to `IID_IDropTarget'
C:\Code-Blocks\Libraries\lib\libfltk.a(fl_dnd.o):fl_dnd.cxx:(.text$_ZN12FLDropTarget4DropEP11IDataObjectm8tagPOINTPm+0x208):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(fl_dnd.o):fl_dnd.cxx:(.text$_ZN12FLDropTarget9DragEnterEP11IDataObjectm8tagPOINTPm+0x205):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(fl_dnd.o):fl_dnd.cxx:(.text$_ZN12FLDropSource14QueryInterfaceERK5_GUIDPPv+0x13):: undefined reference to `IID_IUnknown'
C:\Code-Blocks\Libraries\lib\libfltk.a(fl_dnd.o):fl_dnd.cxx:(.text$_ZN12FLDropSource14QueryInterfaceERK5_GUIDPPv+0x27):: undefined reference to `IID_IDropSource'
C:\Code-Blocks\Libraries\lib\libfltk.a(fl_dnd.o):fl_dnd.cxx:(.text$_ZN12FLDataObject14QueryInterfaceERK5_GUIDPPv+0x13):: undefined reference to `IID_IUnknown'
C:\Code-Blocks\Libraries\lib\libfltk.a(fl_dnd.o):fl_dnd.cxx:(.text$_ZN12FLDataObject14QueryInterfaceERK5_GUIDPPv+0x27):: undefined reference to `IID_IDataObject'
C:\Code-Blocks\Libraries\lib\libfltk.a(fl_font.o):fl_font.cxx:(.text+0x61):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(fl_font.o):fl_font.cxx:(.text+0x83):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(fl_font.o):fl_font.cxx:(.text+0x95):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(fl_font.o):fl_font.cxx:(.text+0xab):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(fl_font.o):fl_font.cxx:(.text+0x12f):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(fl_font.o):fl_font.cxx:(.text+0x151):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(fl_font.o):fl_font.cxx:(.text+0x163):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(fl_font.o):fl_font.cxx:(.text+0x179):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(fl_font.o):fl_font.cxx:(.text+0x1b8):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(fl_font.o):fl_font.cxx:(.text+0x1da):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(fl_font.o):fl_font.cxx:(.text+0x312):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(fl_font.o):fl_font.cxx:(.text+0x32b):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(fl_font.o):fl_font.cxx:(.text+0x342):: undefined reference to `[email protected]'
C:\Code-Blocks\Libraries\lib\libfltk.a(fl_font.o):fl_font.cxx:(.text+0x34e):: undefined reference to `[email protected]'
:: More errors follow but not being shown.
:: Edit the max errors limit in compiler options...
:: === Build finished: 50 errors, 0 warnings ===

Any help would be greatly appreciated.  I've been having this kind of trouble for quite some time now.  I'm a beginner with C++ and it'd be nice if I could learn to link these libraries correctly.  I've only just learned how to use MSYS and what a great tool it is.  It got rid of my suspicion that because the libraries I had were compiled with a different compiler, MinGW might have a hard time referencing it.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9595
Re: Linking Libraries
« Reply #1 on: July 24, 2007, 07:55:19 pm »
Any help would be greatly appreciated.
You are missing to link against the windows libs. Search on MSDN for each of the symbols the linker complains about. MSDN will tell you which lib(s) you have to link against.
For example "DeleteObject": Find it here:
Find the info about libs as there are: "Library: Use Gdi32.lib" -> written on that webpage
Add "gdi32" to the libs to link against. This libs will most likely eliminate other undefined references, too. So re-start compiling again and then continue with the undefined references remaining.
With regards, Morten.
Ps.: BTW: This is quite basic. Did you ever try to compile a (FLTK) Windows app before?! ;-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual:

Offline CaptFalcon33035

  • Single posting newcomer
  • *
  • Posts: 4
Re: Linking Libraries
« Reply #2 on: July 24, 2007, 08:04:45 pm »
No libraries before.  So far, all I have been developing were console utilities, like base conversions, text compression, and practicing a little with pointers (I still don't get those things that well, but I've got an excellent reference. ;) )

Also, I thought FLTK was supposed to be cross-platform.  How can it be cross-platform if I have to link to Microsoft's libraries?

Thank you so much, man.  I just included GDI32 and I'm down to 17 errors from over 50. :D
« Last Edit: July 24, 2007, 08:08:11 pm by CaptFalcon33035 »

Offline raph

  • Almost regular
  • **
  • Posts: 242
Re: Linking Libraries
« Reply #3 on: July 24, 2007, 08:55:04 pm »
Also, I thought FLTK was supposed to be cross-platform.  How can it be cross-platform if I have to link to Microsoft's libraries?
That's because the window port of fltk do need the windows api to handle windows, controls, etc.