Menu

problem linking Haru pdf library

nenad16x16
2008-04-26
2012-09-26
  • nenad16x16

    nenad16x16 - 2008-04-26

    I'm trying to use Haru to dynamically create a pdf document. However when compiling, the linker gives "undefined reference" for every function from library I put in the code. Not sure if this is a Dev issue or I didn't setup Haru properly.
    I'd appreciate any suggestions on how to fix it. Thanks.

    Here's the example code:

    include <cstdlib>

    include "hpdf.h"

    int main(int argc, char *argv[])
    {
    HPDF_Doc pdf;
    pdf = HPDF_New( 0, NULL );
    }

    And the compile log:

    Compiler: Default compiler
    Building Makefile: "C:\Dev-Cpp\Makefile.win"
    Executing make...
    make.exe -f "C:\Dev-Cpp\Makefile.win" all
    g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"F:/ce/haru/libharu-2.0.8/include"

    g++.exe main.o -o "Project1.exe" -L"C:/Dev-Cpp/lib" F:/ce/haru/libharu-2.0.8/libhpdf.lib

    main.o(.text+0x3a):main.cpp: undefined reference to `_imp__HPDF_New@8'
    collect2: ld returned 1 exit status

    make.exe: *** [Project1.exe] Error 1

    Execution terminated

    Dav version is 4.9.9.2

     
    • cpns

      cpns - 2008-04-28

      You should link both zlib and the PNG library it seems. If the calls you use do not need them, linking the libraries adds no code size overhead because only those object modules required to resolve references are extracted and linked. It is therefore just simpler to list all libraries that may be required.

      Clifford

       
    • cpns

      cpns - 2008-04-26

      If it has a .lib extension rather than a .a extension it is quite possibly not a GNU archive. Not only does it need to be a GNU archive, but it would have had to have been built with MinGW/GCC.

      I took a look at the header file and if you are using the DLL import library rather than the static library you need to define HPDF_DLL_MAKE (add -DHPDF_DLL_MAKE to the compile options). I am guessing, check the documentation.

      Clifford

       
    • nenad16x16

      nenad16x16 - 2008-04-26

      Hmm, I tried linking both - dll import library (.lib) and a static library (.a)
      In both cases I get the same error (the log above is, obviously, from linking with .lib)

      The dll import lib I used came with the package. The static library, I built myself from the source. Again, I tried doing this two ways - first by using original configure/make and compiling with mingw gcc (not the version I use with Dev though) as specified in docs. Second try was just plainly compiling the source as a Dev static library project. In both cases the error persisted when linking it into my program.

       
    • cpns

      cpns - 2008-04-27

      If you used a provided import library, it was most unlikely to be a GNU/MinGW version. The face that the symbol is prefixed imp indicates that it is trying to find a DLL version. If your static library link truely was identical, then it should not have been looking for the imp version.

      Build logs can be subtle, it is better to post them all rather than simply say "its the same except for ....". The log from the library build may have been useful too.

      You can use the nm.exe tool to list all the symbols defined by a library.

      Perhaps not realted to your problem, but you should use

      include <hpdf.h>

      rather than

      include "hpdf.h"

      to make sure that it gets the file from "F:/ce/haru/libharu-2.0.8/include" rather than the source directory.

      Also unrelated; there is a known bug in Dev-C++ that sometimes causes builds in the install directory or sub-folders therof to fail. You should not therefore put your project in C:\Dev-Cpp\ (it is a bad idea even without the bug!)

      Clifford

       
    • nenad16x16

      nenad16x16 - 2008-04-27

      Strange. I get the undefined reference to _imp__HPDF_New in both cases.

      Here's the code again:

      include <cstdlib>

      include <hpdf.h>

      int main(int argc, char *argv[])
      {
      HPDF_Doc pdf;
      pdf = HPDF_New( 0, NULL );
      }

      Compile log when linking with dll import library libhpdf.lib:

      Compiler: Default compiler
      Building Makefile: "F:\ce\test\Makefile.win"
      Executing make...
      make.exe -f "F:\ce\test\Makefile.win" all
      g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"F:/ce/haru/libharu-2.0.8/include"

      g++.exe main.o -o "Project1.exe" -L"C:/Dev-Cpp/lib" ../haru/libharu-2.0.8/libhpdf.lib

      main.o(.text+0x3a):main.cpp: undefined reference to `_imp__HPDF_New@8'
      collect2: ld returned 1 exit status

      make.exe: *** [Project1.exe] Error 1

      Execution terminated

      Compile log when linking with static library libhpdf.a:

      Compiler: Default compiler
      Building Makefile: "F:\ce\test\Makefile.win"
      Executing make...
      make.exe -f "F:\ce\test\Makefile.win" all
      g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"F:/ce/haru/libharu-2.0.8/include"

      g++.exe main.o -o "Project1.exe" -L"C:/Dev-Cpp/lib" ../haru/libharu-2.0.8/libhpdf.a

      main.o(.text+0x3a):main.cpp: undefined reference to `_imp__HPDF_New@8'
      collect2: ld returned 1 exit status

      make.exe: *** [Project1.exe] Error 1

      Execution terminated

      Compile log of the static library build:

      Compiler: Default compiler
      Building Makefile: "F:\ce\harubuild\Makefile.win"
      Executing make clean
      rm -f src/hpdf_annotation.o src/hpdf_array.o src/hpdf_binary.o src/hpdf_boolean.o src/hpdf_catalog.o src/hpdf_destination.o src/hpdf_dict.o src/hpdf_doc.o src/hpdf_doc_png.o src/hpdf_encoder.o src/hpdf_encoder_cns.o src/hpdf_encoder_cnt.o src/hpdf_encoder_jp.o src/hpdf_encoder_kr.o src/hpdf_encrypt.o src/hpdf_encryptdict.o src/hpdf_error.o src/hpdf_ext_gstate.o src/hpdf_font.o src/hpdf_font_cid.o src/hpdf_font_tt.o src/hpdf_font_type1.o src/hpdf_fontdef.o src/hpdf_fontdef_base14.o src/hpdf_fontdef_cid.o src/hpdf_fontdef_cns.o src/hpdf_fontdef_cnt.o src/hpdf_fontdef_jp.o src/hpdf_fontdef_kr.o src/hpdf_fontdef_tt.o src/hpdf_fontdef_type1.o src/hpdf_gstate.o src/hpdf_image.o src/hpdf_image_png.o src/hpdf_info.o src/hpdf_list.o src/hpdf_mmgr.o src/hpdf_name.o src/hpdf_null.o src/hpdf_number.o src/hpdf_objects.o src/hpdf_outline.o src/hpdf_page_label.o src/hpdf_page_operator.o src/hpdf_pages.o src/hpdf_real.o src/hpdf_streams.o src/hpdf_string.o src/hpdf_utils.o src/hpdf_xref.o libhpdf.a

      gcc.exe -c src/hpdf_annotation.c -o src/hpdf_annotation.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_array.c -o src/hpdf_array.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_binary.c -o src/hpdf_binary.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_boolean.c -o src/hpdf_boolean.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_catalog.c -o src/hpdf_catalog.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_destination.c -o src/hpdf_destination.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_dict.c -o src/hpdf_dict.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_doc.c -o src/hpdf_doc.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_doc_png.c -o src/hpdf_doc_png.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_encoder.c -o src/hpdf_encoder.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_encoder_cns.c -o src/hpdf_encoder_cns.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_encoder_cnt.c -o src/hpdf_encoder_cnt.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_encoder_jp.c -o src/hpdf_encoder_jp.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_encoder_kr.c -o src/hpdf_encoder_kr.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_encrypt.c -o src/hpdf_encrypt.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_encryptdict.c -o src/hpdf_encryptdict.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_error.c -o src/hpdf_error.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_ext_gstate.c -o src/hpdf_ext_gstate.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_font.c -o src/hpdf_font.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_font_cid.c -o src/hpdf_font_cid.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_font_tt.c -o src/hpdf_font_tt.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_font_type1.c -o src/hpdf_font_type1.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_fontdef.c -o src/hpdf_fontdef.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_fontdef_base14.c -o src/hpdf_fontdef_base14.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_fontdef_cid.c -o src/hpdf_fontdef_cid.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_fontdef_cns.c -o src/hpdf_fontdef_cns.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_fontdef_cnt.c -o src/hpdf_fontdef_cnt.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_fontdef_jp.c -o src/hpdf_fontdef_jp.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_fontdef_kr.c -o src/hpdf_fontdef_kr.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_fontdef_tt.c -o src/hpdf_fontdef_tt.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_fontdef_type1.c -o src/hpdf_fontdef_type1.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_gstate.c -o src/hpdf_gstate.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_image.c -o src/hpdf_image.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_image_png.c -o src/hpdf_image_png.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_info.c -o src/hpdf_info.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_list.c -o src/hpdf_list.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_mmgr.c -o src/hpdf_mmgr.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_name.c -o src/hpdf_name.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_null.c -o src/hpdf_null.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_number.c -o src/hpdf_number.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_objects.c -o src/hpdf_objects.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_outline.c -o src/hpdf_outline.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_page_label.c -o src/hpdf_page_label.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_page_operator.c -o src/hpdf_page_operator.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_pages.c -o src/hpdf_pages.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_real.c -o src/hpdf_real.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_streams.c -o src/hpdf_streams.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_string.c -o src/hpdf_string.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_utils.c -o src/hpdf_utils.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      gcc.exe -c src/hpdf_xref.c -o src/hpdf_xref.o -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      ar r libhpdf.a src/hpdf_annotation.o src/hpdf_array.o src/hpdf_binary.o src/hpdf_boolean.o src/hpdf_catalog.o src/hpdf_destination.o src/hpdf_dict.o src/hpdf_doc.o src/hpdf_doc_png.o src/hpdf_encoder.o src/hpdf_encoder_cns.o src/hpdf_encoder_cnt.o src/hpdf_encoder_jp.o src/hpdf_encoder_kr.o src/hpdf_encrypt.o src/hpdf_encryptdict.o src/hpdf_error.o src/hpdf_ext_gstate.o src/hpdf_font.o src/hpdf_font_cid.o src/hpdf_font_tt.o src/hpdf_font_type1.o src/hpdf_fontdef.o src/hpdf_fontdef_base14.o src/hpdf_fontdef_cid.o src/hpdf_fontdef_cns.o src/hpdf_fontdef_cnt.o src/hpdf_fontdef_jp.o src/hpdf_fontdef_kr.o src/hpdf_fontdef_tt.o src/hpdf_fontdef_type1.o src/hpdf_gstate.o src/hpdf_image.o src/hpdf_image_png.o src/hpdf_info.o src/hpdf_list.o src/hpdf_mmgr.o src/hpdf_name.o src/hpdf_null.o src/hpdf_number.o src/hpdf_objects.o src/hpdf_outline.o src/hpdf_page_label.o src/hpdf_page_operator.o src/hpdf_pages.o src/hpdf_real.o src/hpdf_streams.o src/hpdf_string.o src/hpdf_utils.o src/hpdf_xref.o

      ar: creating libhpdf.a

      ranlib libhpdf.a

      Execution terminated

      And here are the contents of the both libraries listed with nm:

      http://www.16x16.org/misc/libhpdf_lib_list.txt
      http://www.16x16.org/misc/libhpdf_a_list.txt

       
    • cpns

      cpns - 2008-04-27

      >> Strange. I get the undefined reference to _imp__HPDF_New in both cases.

      That was rather my point. My theory was that when you use the export library, the symbol is not found because it is not a valid GNU/MinGW library, when you use the static library the symbol is not found because the compiled main.o is referencing the DLL symbol. At least that was my theory. But I am not certain why it is doing that since you have not defined HPDF_DLL.

      The documentation does say that you need to compile with -DHPDF_DLL if using the DLL version, but you did not do that (it is always a good idea to start with the library's documentation before asking here).

      Since nm.exe made sense of both files I guess they are both GNU files, but .lib is not the traditional convention for such files - hence my suspicion.

      The MinGW makefile provided with the source includes the -mno-cygwin option in the CFLAGS. I understand that this is used to build MinGW executables from Cygwin so should not be necessary I would have thought.

      Anyway, short of actually building it myself I am at a loss at this point. I may get time to build it and try it later, but not right now - sorry.

      Clifford

       
    • nenad16x16

      nenad16x16 - 2008-04-28

      Clifford, thanks for the insightful replies. I resolved it. To a degree at least.

      The .lib I downloaded is probably not a proper gnu file and this was causing the initial error. I didn't inspect this further since I prefer using the static library anyway.

      Problem with .a file is coming from hpdf.h header. I was constantly using the header that came with the dll package. This version of header explicitly defines HPDF_DLL thus forcing the usage of the imp names from the dll import library. The error was gone when I switched to hpdf.h found in the source code package. This one does not define the above mentioned constant.

      There are still some undefined references though. Judging by the names, I suspect they're from zlib which is one of the Haru dependencies. I'll try to rebuild the library linking in the libz.a.

      Here's the compile log:

      Compiler: Default compiler
      Building Makefile: "F:\ce\test\Makefile.win"
      Executing make clean
      rm -f main.o Project1.exe

      g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"F:/ce/harubuild/include"

      g++.exe main.o -o "Project1.exe" -L"C:/Dev-Cpp/lib" ../haru/libharu-2.0.8/libhpdf.a

      ../haru/libharu-2.0.8/libhpdf.a(hpdf_streams.o)(.text+0xdec):hpdf_streams.c: undefined reference to deflateInit_' ../haru/libharu-2.0.8/libhpdf.a(hpdf_streams.o)(.text+0xea1):hpdf_streams.c: undefined reference todeflateEnd'
      ../haru/libharu-2.0.8/libhpdf.a(hpdf_streams.o)(.text+0xecc):hpdf_streams.c: undefined reference to deflate' ../haru/libharu-2.0.8/libhpdf.a(hpdf_streams.o)(.text+0xee6):hpdf_streams.c: undefined reference todeflateEnd'
      ../haru/libharu-2.0.8/libhpdf.a(hpdf_streams.o)(.text+0xf94):hpdf_streams.c: undefined reference to deflateEnd' ../haru/libharu-2.0.8/libhpdf.a(hpdf_streams.o)(.text+0xff5):hpdf_streams.c: undefined reference todeflate'
      ../haru/libharu-2.0.8/libhpdf.a(hpdf_streams.o)(.text+0x100f):hpdf_streams.c: undefined reference to deflateEnd' ../haru/libharu-2.0.8/libhpdf.a(hpdf_streams.o)(.text+0x10e5):hpdf_streams.c: undefined reference todeflateEnd'
      ../haru/libharu-2.0.8/libhpdf.a(hpdf_streams.o)(.text+0x112f):hpdf_streams.c: undefined reference to `deflateEnd'
      collect2: ld returned 1 exit status

      make.exe: *** [Project1.exe] Error 1

      Execution terminated

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.