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
If you want to use MinGW on cygwin, "-mno-cygwin" option is required. In this case, you have to prepare zlib.a and libpng.a for MinGW.
gcc -o myprogram -O2 -Wall myprogram.c -mno-cygwin -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.
The library files of zlib, pnglib for Microsoft C++ are prepared in win32/msvc directory.
NOTE:
If you prepare libpng.lib and zlib.lib yourself (dont use the files in win32\msvc directory), change /LIBPATH options to appropriate directory name.
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.

### Borland C++

1. Static library
If you installed Haru as a static library, a typical command for compiling on Borland C++ is as follows.
bcc32 -emyprogram.exe -WM -O2 -Iinclude -Iwin32\include -L. -Lwin32\bcc32 libhpdf.lib libpng.lib zlib.lib myprogram.c
The following options must be changed depending on your environment.
[-WM]
In the default setting, Haru is configured to link with multi-thread library.
[-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.
[-L]
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.
The library files of zlib, pnglib for borland c++ are prepared in win32/bcc32 directory.
2. Shared library
If you installed Haru as a shared library(.DLL), a typical command for compiling is as follows.
bcc32 -emyprogram.exe -WM -O2 -Iinclude -DHPDF_DLL -L. -Lwin32\bcc32 libhpdf.lib myprogram.c
-DHPDF_DLL directive must be add to compile a program which uses libhpdf.dll.