Skip to content

Configuration of Third Party Libraries for Nana

dnso86 edited this page Apr 21, 2019 · 10 revisions

This page gives a brief description to illustrate how to configure third party libraries for Nana(1.2 and later).

  • PNG support requires libpng and zlib
  • JPEG supoort requires libjpeg

Some switches in "nana/config.hpp" file determine whether enable/disable support of certain features.

  • NANA_ENABLE_PNG for PNG support
  • NANA_ENABLE_JPEG for JPEG support

Default configuration disables these features. To enable a feature, just follow the following instruction.

Use the precompiled external libraries bundled with Nana

These third party libraries are precompiled for Windows, you can download the binaries at https://sourceforge.net/projects/nanapro/files/extrlib

Open the URL you can see some folders named with compiling environment, choose a right folder which is your compiling environment, download one or more binaries which are required by the feature.

Open the Nana's extrlib directory in your system, create a directory with name of compiling environment which you use like the folders described above.

  • VC2013 for Visual Studio 2013
  • VC2015 for Visual Studio 2015
  • MinGW for Code::Blocks

For example, if the path of Nana is C:\Nana, then the extrlib directory is C:\Nana\extrlib. Create a directory named VC2015 in extrlib directory if you use Visual Studio 2015(refer to C:\Nana\extrlib\VC2015 as %extrlib% from now on).

Extract files from the compressed file to the %extrlib%. Then you can see some static libraries(.lib/.a files) and a directory called nana_extrlib. The nana_extrlib includes some library header files, these header files are included by Nana for a certain feature.

Modify the macro in header file "nana/config.hpp" for a feature which is prepared.

  • define NANA_ENABLE_PNG for support of PNG
  • define NANA_ENABLE_JPEG for support of JPEG

At last, rebuild Nana.

Use the third party libraries from the operating system

Install the open source library in your system.

Open "nana/config.hpp", define NANA_ENABLE_XXX to enable the feature, then remove the marco NANA_LIBPNG or NANA_LIBJPEG to make Nana include library header file from operating system, not the header file in %extrlib%/nana_extrlib.

Rebuild Nana.

Enable the PNG support in Visual Studio 2015

(This method also applies to other third party libraries)

libpng requires zlib, download the libpng and zlib in VC2015 folder at https://sourceforge.net/projects/nanapro/files/extrlib.

Extract these 2 libraries to the directory C:\Nana\extrlib\VC2015.

Open <nana/config.hpp> file(C:\Nana\include\nana\config.hpp), you can find a line of comment like this

//#define NANA_ENABLE_PNG	//!

Cancel the comment to enable the support of PNG

///////////////////
//Support for PNG
//	Define the NANA_ENABLE_PNG to enable the support of PNG.
//
#define NANA_ENABLE_PNG	//!
#if defined(NANA_ENABLE_PNG)
	#define NANA_LIBPNG	//Comment it to use libpng from operating system.
#endif

Rebuild Nana and create a new application for trial.

#include <nana/gui.hpp>
#include <nana/gui/widgets/picture.hpp>
#include <nana/gui/place.hpp>

int main()
{
    using namespace nana;
    form fm;
    picture pic(fm);

    place plc(fm);    //Layout
    plc.div("margin=5 PIC");
    plc["PIC"]<<pic;
    plc.collocate();

    pic.load(L"image.png"); //Display the PNG file
    fm.show();
    exec();
}

Add %extrlib%\VC2015 to the application's library directories. In Solution Explorer, right click the solution, choose Properties to open Property Pages window, Configuration Properties->VC++ Directories, Add C:\Nana\extrlib\VC2015 to Library Directories.

Link the static libraries of libpng and zlib.