Sunday, August 7, 2011

Tutorial: Code::Blocks with FLTK




Building the FLTK library is pretty easy.
Building the library on Windows
Stuff you will need:
CMake
MinGW Compiler System
CmdHere Powertoy

Make sure you have a MinGW in your PATH. On Windows XP you just need to right click on My Computer
and select Advanced tab. Press the "Environment Variables" and add the MinGW folder path into the PATH variable. In some cases MinGW setup lets you add this automatically.

Lets setup the CMake. Run the CMake-GUI application and setup the extracted FTLK library folder.
I was testing this with stable 1.3 and 1.1.10 versions.

On first time run you need press "Configure". Options window should appear. From the list select
"MinGW Makefiles" and select "Specify native compilers".
Browse for the C and C++ compilers in MinGW folder.
For the C compiler select gcc.exe and for C++ compiler select
g++.exe . Yes not the c++.exe :)



Your settings should look like this. We don't want to use the system libraries and build all the examples.
Hit the Configure button and later Generate. All the red warning should be gone. 

Note:
For 1.1.10 version you need to open the CMakeLists.txt from \src\ folder and 
and in the end of file add the following lines:
if(WIN32)
   target_link_libraries(fltk comctl32)
endif(WIN32)

Now we have configured and build all makefiles we need. Lets build the library and FLUID.
If you have configured Comand line shell in explorer from the link above you just need to right click
and on the extracted folder of FTLK that includes all the source and test files,and select "Open Command Window Here". If you don't have such option press Windows Logo key + R or from Start menu select
"Run..." and type cmd in opened window. 

Now you need to execute command pushd
And execute command mingw32-make or just make. Look the image bellow.

If everything alright you should get everything build 100% and all FTLK libraries plus FLUID app in the
FTLK bin folder. Or in the folder defined in CMake. Copy those libraries into MinGW installation lib folder.
I actually added FLTK library folder into Code::Blocks search directories. You can find those in 
Settings->Compiler and debugger... -> Global compiler settings -> Search directories tab. 

How to build libraries on Linux?

Everything is quite the same. You need to download cmake and cmake-gui (probably with QT interface).
After generating makefiles right click on the FTLK source folder and open the terminal.
In terminal enter make command. That's all. If you get some errors you might be missing some libraries 
and dev packages.

When building from the imported MS Visual Studio files on Code::Blocks don't forget to link those libraries:
  • ftlk
  • uuid
  • ole32
  • comctl32
  • comdlg32
  • gdi32



If you get and error that some X function cannot be found in libfltka you may want to look in Google 
for that function to see what library you will need to link. If you are building a new project using wizard simply make new folder called include in FLTK library folder and copy here the FL folder since Code::Blocks Project wizard always looks for include folder. 

Have fun with codding! 

You can download my Win32 build version with 4 extra Gleam themes.  




2 comments:

Andrew said...

Thank you! This was immensely helpful and simple. Thank you again!

Gintas said...

You are welcome! It was really confusing at first for me too.