Menu

MinGW compiling errors

Help
drummerp
2012-03-23
2012-10-31
  • drummerp

    drummerp - 2012-03-23

    I've been trying to compile FreeImage for use in my program, using MinGW
    version...er...well, the GCC version is 4.4.1. Anyway, I'm using MSYS to
    compile it, using the commands:

    set FREEIMAGE_LIBRARY_TYPE=STATIC
    make -f Makefile.minGW

    It compiles for several minutes, before I get the following errors:

    Source/LibRawLite/./src/libraw_datastream.cpp: In constructor
    'LibRaw_windows_datastream::LibRaw_windows_datastream(const TCHAR)':
    Source/LibRawLite/./src/libraw_datastream.cpp:472: error: 'runtime_error' is
    not a member of 'std'
    Source/LibRawLite/./src/libraw_datastream.cpp: In member function
    'LibRaw_windows_datastream::Open(void
    ):
    Source/LibRawLite/./src/libraw_datastream.cpp:504: error: 'runtime_error' is
    not a member of 'std'
    Source/LibRawLite/./src/libraw_datastream.cpp:507: error: '::GetFileSizeEx'
    has not been declared
    Source/LibRawLite/./src/libraw_datastream.cpp:508: error: 'runtime_error' is
    not a member of 'std'
    Source/LibRawLite/./src/libraw_datastream.cpp:512: error: 'runtime_error' is
    not a member of 'std'
    make: *** Error 1

    I'm afraid to go messing around in the source code, I'm not the best
    programmer... Anyone seen this before or know how to fix it?

     
  • drummerp

    drummerp - 2012-03-25

    Thank you, that fixed the problem. Thanks very much for the help.

     
  • drummerp

    drummerp - 2012-03-25

    Actually, I seem to be having a new problem now... I built FreeImage as a
    static library (FREEIMAGE_LIBRARY_TYPE was set to STATIC in the Makefile), and
    am now linking my program against FreeImage.a. However, for some reason I
    still get "undefined reference to _imp__FunctionName@num" errors when
    linking my program, at every invocation of a FreeImage function:

    In function `Z9loadImageRKSsPhRiS2_':
    undefined reference to `_imp__FreeImage_GetFileType@8'
    undefined reference to `_imp__FreeImage_GetFIFFromFilename@4'
    |undefined reference to `_imp__FreeImage_FIFSupportsReading@4'
    undefined reference to `_imp__FreeImage_Load@12'
    undefined reference to `_imp__FreeImage_ConvertTo32Bits@4'
    undefined reference to `_imp__FreeImage_Unload@4'
    undefined reference to `_imp__FreeImage_GetWidth@4'
    undefined reference to `_imp__FreeImage_GetHeight@4'
    undefined reference to `_imp__FreeImage_GetPitch@4'
    undefined reference to `_imp__FreeImage_ConvertToRawBits@32'
    undefined reference to `_imp__FreeImage_Unload@4'
    ||=== Build finished: 11 errors, 0 warnings ===|
    
     
  • Carsten Klein

    Carsten Klein - 2012-03-25

    Ok, this is a problem not related to FreeImage. Obviously, you are having
    problems to link against the GCC-generated static library file (*.a file). I
    assume, that you compile your code that links to the static FreeImage library
    also MinGW, too. Currently, I have no idea what's going wrong there. I
    actually have never tested using that static FreeImage library from MinGW (at
    least I can't remeber that). I will have a closer look at this next week and
    hope to get back to you soon with some useful hints.

    Carsten

     
  • drummerp

    drummerp - 2012-03-25

    Okay, thank you very much. I look forward to hearing your discoveries.

     
  • Carsten Klein

    Carsten Klein - 2012-03-27

    Hi,

    OK, there are several problems with your build. First, when linking
    statically, GCC assumes archive files (*.a) to be prefixed with 'lib'.
    Basically, that's a shortcoming in the MinGW Makefile and I will provide an
    updated version soon.

    However, you can do two things to handle this. You could either rename file
    FreeImage.a to libFreeImage.a or you could add the 'lib' prefix to file
    Makefile.mingw in line 73. Just make this line appear STATICLIB =
    lib$(TARGET).a an re-run the build process after a 'make clean'.

    There is another problem with you build. When linking statically to FreeImage,
    you need to define symbol FREEIMAGE_LIB prior to including header file
    FreeImage.h. This header file is used for both creating and importing the DLL
    as well as for static linking. With that symbol (among others), import/export
    behavior as well as calling convention is controlled. By default, FreeImage.h
    assumes that you link to FreeImage.dll. You can have a look at this in
    FreeImage.h, starting at line 39. That's also described on the FreeImage
    project page under FAQ http://freeimage.sourceforge.net/faq.html. So, I recommend adding -DFREEIMAGE_LIB to
    both your C and C++ compiler flags.

    Additionally, with static linking, you need to call FreeImage_Initialise
    before you use FreeImage and also FreeImage_DeInitialise before you are done
    with FreeImage or when you application exits. When linking dynamically, the
    DLL does this job for you.

    In the end, you also need to add both libraries wsock32 and ws2_32 to the list
    of required libraries. These are the Windows Winsock libraries, needed by
    LibRaw. So, you also need to add -lwsock32 -lws2_32 to your linker command
    line.

    Carsten

     

Log in to post a comment.