Technical information for compiling and linking the software application MkBGFire by using FLTK and OpenGL


The task is to create an executable file of mygl.cxx by using FLTK and OpenGL.

Linux - dynamic linking

# sudo add-apt-repository universe
# sudo apt install g++ gcc libc6-dev libfltk1.3 libfltk-gl1.3 libfltk1.3-dev libgl1-mesa-dev
# c++ mygl.cxx -o mygl -lfltk -lfltk_gl -lGL
# ./mygl

Linux - static linking

Download FLTK from http://www.fltk.org/software.php

# sudo apt install g++ gcc libc6-dev libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev libxrender-dev libxcursor-dev libxft-dev libfontconfig1-dev
# cd ~/work/
# tar -xvf fltk-1.3.4-2-source.tar.gz
# cd fltk-1.3.4-2/
# ./configure
# make
# cd ~/work/
# mkdir -p fltk/include/ fltk/lib/
# cp -r fltk-1.3.4-2/FL/ fltk/include/
# cp -r fltk-1.3.4-2/lib/*.a fltk/lib/
# c++ mygl.cxx -o mygl -Ifltk/include -Lfltk/lib -lfltk -lfltk_gl -lGL -ldl -lX11 -lXext -lXfixes -lXrender -lXcursor -lXft -lfontconfig
# ./mygl

Packages libxft-dev and libfontconfig1-dev are required for font management. Find out the respective flags for static compilation with fltk-config --ldstaticflags.

Windows - dynamic linking

GCC/MinGW/TDM compilers generate *.a static libraries. Visual Studio C++ compiler generates *.lib static libraries (see fltk.lib.vcxproj) and *.dll dynamic libraries (see fltkdll.vcxproj), project files are in fltk-1.3.4-2\ide\VisualC2010.

http://www.fltk.org/doc-1.3/opengl.html#opengl3
http://www.fltk.org/articles.php?L371
http://www.fltk.org/articles.php?L372

Windows - static linking

  1. Download TDM-GCC 5.1.0 and install to C:\work\TDM-GCC-64.
    Select tdm64-gcc-5.1.0-2.exe for the 64-bit version.
  2. Download mingw-get-setup and install to C:\work\MinGW
    Mark for installation mingw-developer-toolkit and msys-base.
    Then select Installation → Apply Changes.
  3. Start → Search → Environment Variables → Add the following to PATH:
    C:\work\TDM-GCC-64\bin;C:\work\MinGW\bin;C:\work\MinGW\msys\1.0\bin
  4. Download FLTK from http://www.fltk.org/software.php.

Start an MSYS shell from C:\work\MinGW\msys\1.0\msys.bat:

# cd /c/work/
# tar -xvf fltk-1.3.4-2-source.tar.gz
# cd fltk-1.3.4-2/
# ./configure
# make
# cd /c/work/
# mkdir -p fltk/include/ fltk/lib/
# cp -r fltk-1.3.4-2/FL/ fltk/include/
# cp -r fltk-1.3.4-2/lib/*.a fltk/lib/

Start a Windows command prompt:

> cd C:\work
> x86_64-w64-mingw32-c++ mygl.cxx -o mygl.exe -Ifltk/include -Lfltk/lib -lfltk -lfltk_gl -lopengl32 -mwindows -lcomctl32 -lole32 -luuid
> .\mygl.exe

Flag -mwindows creates a no-console Windows executable, if console window is needed, replace that flag by -lgdi32 -lcomdlg32.

For all compilations, flags -s -O1 can be used, for stripping the executable of debugging symbols and for optimizations O1, O2, O3, respectively. Flag -save-temps can be used to save the preprocessed source file, in *.i for C and *.ii for C++.

Sources:
https://groups.google.com/forum/#!topic/ppp-public/CuTWEfUcPiw
https://stackoverflow.com/questions/29329016/link-failure-undefined-references-to-graphical-functions
https://stackoverflow.com/questions/47058727/link-fltk-with-g
https://stackoverflow.com/questions/22314120/imp-link-errors-using-g-running-under-mingw
https://stackoverflow.com/questions/3933027/how-to-get-the-gl-library-headers
https://stackoverflow.com/questions/30154115/fltk-complains-about-gcc-on-windows
https://github.com/mmgen/mmgen/wiki/Install-MinGW-64-and-MSYS-on-Microsoft-Windows
http://tdm-gcc.tdragon.net/bugs
https://sourceforge.net/p/mingw-w64/mailman/message/34523082/

Statically compiled libraries used for versions ≤ 0.9.2 and ≥ 0.9.3 can be downloaded here. The first archive contains FLTK 1.3.4-2 for Windows 64-bit, the second archive contains FLTK 1.3.4-2, PNGLIB 1.2.7, ZLIB 1.2.11 for Windows 32-bit and 64-bit.

Download the source code for v0.9.5 and read the documentation for v0.9.5.


Main page