Haru Free PDF Library
home | download | documentation | examples | sourceforge | forums

Compile Your Program

GCC

1. Static library
If you installed Haru as a static library, a typical command for compiling on gcc is as follows.

gcc -o myprogram -O2 -Wall myprogram.c -lhpdf -lpng -lz -lm

"-lm" option is not required according to the version of gcc.
"-lpng" option is not required  when a program does not use a png image.
"-mno-cygwin" option is required to use MinGW on cygwin.

If include files and libhpdf.a are in a directory that the compiler and linker cannot find out,  add -I and -L options.
For example,

gcc -o myprogram -O2 -Wall myprogram.c -L../../ -I../include -lhpdf -lpng -lz -lm

2. Shared library
If you installed Haru as a shared library, you have to add "-DHPDF_SHARED" option to compiling command.

gcc -o myprogram -O2 -Wall myprogram.c -DHPDF_SHARED -lhpdf -lpng -lz -lm

If include files and libhpdf.a are in a directory that the compiler and linker cannot find out,  add -I and -L options.
For example,
If you use MinGW,  use "-DHPDF_DLL" instead of "-DHPDF_SHARED".

gcc -o myprogram -O2 -Wall myprogram.c -L../../ -I../include -DHPDF_SHARED -lhpdf -lpng -lz -lm

3. Compiling programs in C++
The compiling command for a C++ is almost the same as C except for adding "-lstdc++". 

gcc -o myprogram -O2 -Wall myprogram.c -lhpdf -lpng -lz -lm -lstdc++

Microsoft VC++

1. Static library
If you installed Haru as a static library, a typical command for compiling on VC++ is as follows.

cl -Femyprogram.exe -MT -O2 -Iinclude -Iwin32\include myprogram.c /link /LIBPATH:. /LIBPATH:win32\msvc libhpdf.lib libpng.lib zlib.lib

The following options must be changed depending on your environment.

[-MT]
In the default setting, Haru is configured to link with LIBCMT.LIB.

NOTE:
libpng.lib and zlib.lib provided in win32\msvc directory are configured using LIBCMT.LIB. If you want to use MSVCRTXX, you should builed libpng.lib and zlib.lib yourself with -MD option.

[-I]
Because of "hpdf_*.h" and header files for zlib/pnglib are required to compile a program, add "include" and "win32\include" directory to the list of directories to be searched for header files.

[/LIBPATH]
To link libhpdf.lib, zlib.lib, libpng.lib, it needs to add directories of these files to the list of directories to be searched for library files.

NOTE:
If you prepare libpng.lib and zlib.lib yourself (dont use the files in win32\msvc directory), change this directive.

2. Shared library
If you installed Haru as a shared library(.DLL), a typical command for compiling is as follows.

cl -Femyprogram.exe -MT -O2 -Iinclude -DHPDF_DLL myprogram.c /link /LIBPATH:. libhpdf_dll.lib

-DHPDF_DLL directive must be add to compile a program which uses libhpdf.dll.