Menu

Compilation problem with MinGW

Help
2015-03-07
2015-05-29
  • Timyus Vegetari

    Timyus Vegetari - 2015-03-07

    Hello,

    I want to compile FreeImage on Windows 7 with MinGW in static because I don't want to use dll.
    I met a problem during the compilation of the sources. On the cmd, I go to FreeImage directory where they are makefiles, etc... I run the commands "set FREEIMAGE_LIBRARY_TYPE=STATIC" and "make -f Makefile.mingw". The PATH for make is ok, and I copied mingw32-make.exe to make.exe in the bin of MinGW. The compilation run, but to the end there is the problem.

    cp libFreeImage.a Dist/libFreeImage.a
    process_begin: CreateProcess(NULL, cp libFreeImage.a Dist/libFreeImage.a, ...) failed.
    make (e=2): Le fichier spécifié est introuvable.
    (In English : The specified file is not found)
    make: *** [Dist/libFreeImage.a] Error 2

    The file libFreeImage.a exist and is in the directory where I run the compilation.
    And when I run "make clean" there a similar problem.

    ... List of files .o which exist in the directories , ...) failed
    make (e=2): Le fichier spécifié est introuvable.
    make[1]: *** [clean] Error 2
    make[1]: Leaving directory `C:/.../FreeImage3160'
    make: *** [clean] Error 2

    This is my problem :(

    And other question, how have the file libFreeImage for debug mode ? libFreeImaged.a like equivalent of FreeImaged.lib ?

     
  • Carsten Klein

    Carsten Klein - 2015-03-07

    Hi Timyus,

    the MinGW Makefile does not use the Windows commands copy and del for copying and deleting files (the latter is required by the 'clean' target), since these have some limitations when compared to the corresponding Linux commands. So, the compiled static library as well as file FreeImage.h are copied into the Dist folder using a command named cp.

    As it is also mentioned in file README.minGW (Prerequisites, 6.), building FreeImage on Windows with MinGW also requires some Linux-like file tools (cp and rm). I recommend getting the CoreUtils package of the GnuWin32 project http://gnuwin32.sourceforge.net/packages.html. You can install it with an installer or simply download some zip archives (Binaries and Dependencies) and extract both into a common base directory (e.g. C:\Program Files (x86)\GnuWin32). Then, add the extracted 'bin' directory (under the above directory) to your PATH environment variable. Then, make should no longer exit with that error.

    Currently, there is no support for building debug versions of both the shared or static library. Maybe I will add support for this (via an environment variable like I did for selecting the shared/static type of the library).

    However, you could just modify the Makefile yourself. In lines 68 and 70, change options -O3 to -g2 and in lines 68, 70 and 72 change Win32 API defines -DNDEBUG to -D_DEBUG. Additionally, in line 76, change make variable TARGET to FreeImaged.

    Carsten

     
  • Timyus Vegetari

    Timyus Vegetari - 2015-03-16

    Thank you for your solution. I add a precision.
    I followed your suggestions and I continued to meet a problem. I set the variable FREEIMAGE_LIBRARY_TYPE=STATIC, but the compilation continued to try to make dll. I did go in the makefile.mingw and I saw this in the line 86 :
    # The FreeImage library type defaults to SHARED.
    FREEIMAGE_LIBRARY_TYPE ?= SHARED

    I change the value to STATIC and the problem is resolved. I don't know what your think about this.

     
  • Carsten Klein

    Carsten Klein - 2015-03-16

    Hi Timyus,

    the line you've changed should work as expected in its original version: assigning with the ?= operator assigns the new value only, if the variable is undefined. So, basically, this is just setting a default value, which, by contract is SHARED.

    Where and how did you set variable FREEIMAGE_LIBRARY_TYPE? Actually, you should be able to set this as a DOS environment variable:

    C:\FreeImage>set FREEIMAGE_LIBRARY_TYPE=STATIC
    
    C:\FreeImage>make
    

    Or you could uncomment line 18 in Makefile.mingw:

    [...]
    # Uncomment this variable to make a static library. This may
    # also be specified as an environment variable and can hold
    # any of STATIC and SHARED and must be in uppercase letters.
    # Default: SHARED
    #FREEIMAGE_LIBRARY_TYPE = STATIC
    
    # Redefine the compiler (CC defaults to ´cc´ for MinGW's make,
    [...]
    

    I just tried both versions on my box and everything worked as expected.

    Carsten

     
  • Timyus Vegetari

    Timyus Vegetari - 2015-03-16

    I meet a new problem and this time to compile my program. I added the good directories for include and lib as well as the files generated by the compilation of FreeImage. I even wrote #define FREEIMAGE_LIB just before #include <FreeImage.h>.
    I obtain this:

    C:\CodeBlocks\MinGW\FreeImage\lib\libFreeImaged.a(libraw_cxx.o)||In function `ZN6LibRaw20dcraw_make_mem_thumbEPi':|
    C:...\FreeImage\Source\LibRawLite.\src\libraw_cxx.cpp|1940|undefined reference to `htons@4'|
    C:\CodeBlocks\MinGW\FreeImage\lib\libFreeImaged.a(libraw_cxx.o)||In function `ZN6LibRaw12unpack_thumbEv':|
    C:...\FreeImage\Source\LibRawLite.\src\libraw_cxx.cpp|2355|undefined reference to `ntohs@4'|
    C:\CodeBlocks\MinGW\FreeImage\lib\libFreeImaged.a(dcraw_common.o)||In function `ZN6LibRaw7getrealEi':|
    C:...\FreeImage\Source\LibRawLite.\internal\dcraw_common.cpp|137|undefined reference to `ntohs@4'|
    C:\CodeBlocks\MinGW\FreeImage\lib\libFreeImaged.a(dcraw_common.o)||In function `ZN6LibRaw11read_shortsEPti':|
    C:...\FreeImage\Source\LibRawLite.\internal\dcraw_common.cpp|148|undefined reference to `ntohs@4'|
    C:\CodeBlocks\MinGW\FreeImage\lib\libFreeImaged.a(dcraw_common.o)||In function `ZN6LibRaw12sony_decryptEPjiii':|
    C:...\FreeImage\Source\LibRawLite.\internal\dcraw_common.cpp|2585|undefined reference to `htonl@4'|
    C:\CodeBlocks\MinGW\FreeImage\lib\libFreeImaged.a(dcraw_common.o)||In function `ZN6LibRaw13sony_load_rawEv':|
    C:...\FreeImage\Source\LibRawLite.\internal\dcraw_common.cpp|2627|undefined reference to `ntohs@4'|
    etc...

    I don't know if my lib compilation was correct. The compilation of the lib is complete and without error. I tried several times, even without debug, but nothing changes it :(

     
  • Timyus Vegetari

    Timyus Vegetari - 2015-03-16

    Oh sorry, I didn't see your response. I will try with this information.

     
  • Carsten Klein

    Carsten Klein - 2015-03-16

    Hi,

    the undefined reference errors occurring when your application is compiled have nothing to do with building the static FreeImage library. The point is, that LibRawLite (a library for loading/saving raw images, used by FreeImage) do require TCP/IP socket functions (like htons, htonl etc.).

    On Windows, these functions are part of the Winsock2 library (Winsock2.h, Ws2_32.lib and Ws2_32.dll). When building a DLL, a dependency for this library is added to the DLL (by passing -lws2_32 to the linker, see line 47 of Makefile.mingw). With that, FreeImage.dll knows about this dependency and ensures Ws2_32.dll is properly loaded during its execution time.

    However, there is no such dependency mechanism for a static library (which basically is nothing more than an archive file containing some object files). So, you as the programmer have to ensure, that Ws2_32.dll gets loaded when your application starts - simply by adding ws2_32 as an additional library to your application.

    Carsten

     
  • Timyus Vegetari

    Timyus Vegetari - 2015-03-16

    Thank you for your help. I still miss knowledge, but I learn as I can :)

    Have a good day :)

     
  • BratSinot

    BratSinot - 2015-03-26

    Hello there!

    In OpenEXR, in file "Source/OpenEXR/llmf/lmfSystemSpecific.h" we have two functions EXRAllocAligned() and EXRFreeAligned(). These function use posix_memalign()+free() when defined __GNUC__ or _aligned_malloc()+_aligned_free() when defined _MSC_VER.

    Under MinGW defined __GNUC__ macros, but posix_memalign() has no under MinGW (only in glibc under GNU/Linux and some other libc under other POSIX), so we must use _aligned_malloc() instead.

     

    Last edit: BratSinot 2015-03-26
  • Carsten Klein

    Carsten Klein - 2015-03-27

    Hi Brat,

    actually, this seems to be a problem with MinGW and OpenEXR. If SSE is activated by -msse (or -msse2 etc.), the described compilation error occurs.

    In file FreeImage\Source\OpenEXR\IlmImf\ImfSystemSpecific.h, the test in line 57 should better be:

    #if defined(__GNUC__) && !defined(__MINGW32__)
    

    However, since there is no standard _aligned_malloc in MinGW (there are some C files out there which provide aligned_malloc and aligned_free functions, but these are no standard MinGW files), no other changes should be applied to this file. This causes MinGW to use the // generic compiler branch staring in line 113, which just maps these functions to standard malloc and free.

    However, for standard Make builds using MinGW and the provided Makefile.mingw, that's all not an issue, since any SSE option (which is highly hardware/platform specific) is not enabled by FreeImage's Makefile.

    @Hervé: Anyway, are you able to submit this patch request to the OpenEXR project?

    Carsten

     
  • Neo

    Neo - 2015-05-03

    I also have problems when building FI using mingw:

    Source/OpenEXR/./IlmImf/ImfFastHuf.cpp:110: error: integer constant is too large for "long" type
    Source/OpenEXR/./IlmImf/ImfFastHuf.cpp:247: warning: converting of negative value -0x000000001' toImath_2_2::Int64'
    Source/OpenEXR/./IlmImf/ImfFastHuf.cpp: In member function `void Imf_2_2::FastHufDecoder::buildTables(Imath_2_2::Int64,
    Imath_2_2::Int64
    )':
    Source/OpenEXR/./IlmImf/ImfFastHuf.cpp:355: error: integer constant is too large for "long" type
    Source/OpenEXR/./IlmImf/ImfFastHuf.cpp:365: error: integer constant is too large for "long" type
    Source/OpenEXR/./IlmImf/ImfFastHuf.cpp:420: error: integer constant is too large for "long" type
    Source/OpenEXR/./IlmImf/ImfFastHuf.cpp:430: error: integer constant is too large for "long" type
    make: *** [Source/OpenEXR/./IlmImf/ImfFastHuf.o] Error 1

    Neo@vpc-neo-w2k /c/Build/FreeImage
    $ gcc -v
    Reading specs from c:/mingw/bin/../lib/gcc/mingw32/3.4.5/specs
    Configured with: ../gcc-3.4.5-20060117-3/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --target=mingw3
    2 --prefix=/mingw --enable-threads --disable-nls --enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry --d
    isable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enable-java-gc=boehm --disable-l
    ibgcj-debug --enable-interpreter --enable-hash-synchronization --enable-libstdcxx-debug
    Thread model: win32
    gcc version 3.4.5 (mingw-vista special r3)

     
  • Neo

    Neo - 2015-05-03

    $ gcc -v
    Using built-in specs.
    COLLECT_GCC=c:\mingw\bin\gcc.exe
    COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/i686-w64-mingw32/4.9.2/lto-wrapper.exe
    Target: i686-w64-mingw32
    Configured with: ../../../src/gcc-4.9.2/configure --host=i686-w64-mingw32 --build=i686-w64-mingw32 --target=i686-w64-min
    gw32 --prefix=/mingw32 --with-sysroot=/c/mingw492/i686-492-win32-dwarf-rt_v4-rev2/mingw32 --with-gxx-include-dir=/mingw3
    2/i686-w64-mingw32/include/c++ --enable-shared --enable-static --disable-multilib --enable-languages=ada,c,c++,fortran,o
    bjc,obj-c++,lto --enable-libstdcxx-time=yes --enable-threads=win32 --enable-libgomp --enable-libatomic --enable-lto --en
    able-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-s
    jlj-exceptions --with-dwarf2 --disable-isl-version-check --disable-cloog-version-check --disable-libstdcxx-pch --disable
    -libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-sy
    mvers --with-gnu-as --with-gnu-ld --with-arch=i686 --with-tune=generic --with-libiconv --with-system-zlib --with-gmp=/c/
    mingw492/prerequisites/i686-w64-mingw32-static --with-mpfr=/c/mingw492/prerequisites/i686-w64-mingw32-static --with-mpc=
    /c/mingw492/prerequisites/i686-w64-mingw32-static --with-isl=/c/mingw492/prerequisites/i686-w64-mingw32-static --with-cl
    oog=/c/mingw492/prerequisites/i686-w64-mingw32-static --enable-cloog-backend=isl --with-pkgversion='i686-win32-dwarf-rev
    2, Built by MinGW-W64 project' --with-bugurl=http://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -I/c/mingw492/i
    686-492-win32-dwarf-rt_v4-rev2/mingw32/opt/include -I/c/mingw492/prerequisites/i686-zlib-static/include -I/c/mingw492/pr
    erequisites/i686-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -I/c/mingw492/i686-492-win32-dwarf-rt_v4-rev2/mingw32/o
    pt/include -I/c/mingw492/prerequisites/i686-zlib-static/include -I/c/mingw492/prerequisites/i686-w64-mingw32-static/incl
    ude' CPPFLAGS= LDFLAGS='-pipe -L/c/mingw492/i686-492-win32-dwarf-rt_v4-rev2/mingw32/opt/lib -L/c/mingw492/prerequisites/
    i686-zlib-static/lib -L/c/mingw492/prerequisites/i686-w64-mingw32-static/lib -Wl,--large-address-aware'
    Thread model: win32
    gcc version 4.9.2 (i686-win32-dwarf-rev2, Built by MinGW-W64 project)

    $ make -f Makefile.mingw
    g++ -O3 -fexceptions -Wno-ctor-dtor-privacy -DNDEBUG -DWINVER=0x0500 -DFREEIMAGE_EXPORTS -DOPJ_STATIC -DLIBRAW_NODLL -in
    clude stdexcept -I. -ISource -ISource/Metadata -ISource/FreeImageToolkit -ISource/LibJPEG -ISource/LibPNG -ISource/LibT
    IFF4 -ISource/ZLib -ISource/LibOpenJPEG -ISource/OpenEXR -ISource/OpenEXR/Half -ISource/OpenEXR/Iex -ISource/OpenEXR/Ilm
    Imf -ISource/OpenEXR/IlmThread -ISource/OpenEXR/Imath -ISource/OpenEXR/IexMath -ISource/LibRawLite -ISource/LibRawLite/d
    craw -ISource/LibRawLite/internal -ISource/LibRawLite/libraw -ISource/LibRawLite/src -ISource/LibWebP -ISource/LibJXR -I
    Source/LibJXR/common/include -ISource/LibJXR/image/sys -ISource/LibJXR/jxrgluelib -c Source/FreeImage/BitmapAccess.cpp -
    o Source/FreeImage/BitmapAccess.o
    g++ -O3 -fexceptions -Wno-ctor-dtor-privacy -DNDEBUG -DWINVER=0x0500 -DFREEIMAGE_EXPORTS -DOPJ_STATIC -DLIBRAW_NODLL -in
    clude stdexcept -I. -ISource -ISource/Metadata -ISource/FreeImageToolkit -ISource/LibJPEG -ISource/LibPNG -ISource/LibT
    IFF4 -ISource/ZLib -ISource/LibOpenJPEG -ISource/OpenEXR -ISource/OpenEXR/Half -ISource/OpenEXR/Iex -ISource/OpenEXR/Ilm
    Imf -ISource/OpenEXR/IlmThread -ISource/OpenEXR/Imath -ISource/OpenEXR/IexMath -ISource/LibRawLite -ISource/LibRawLite/d
    craw -ISource/LibRawLite/internal -ISource/LibRawLite/libraw -ISource/LibRawLite/src -ISource/LibWebP -ISource/LibJXR -I
    Source/LibJXR/common/include -ISource/LibJXR/image/sys -ISource/LibJXR/jxrgluelib -c Source/FreeImage/ColorLookup.cpp -o
    Source/FreeImage/ColorLookup.o
    g++ -O3 -fexceptions -Wno-ctor-dtor-privacy -DNDEBUG -DWINVER=0x0500 -DFREEIMAGE_EXPORTS -DOPJ_STATIC -DLIBRAW_NODLL -in
    clude stdexcept -I. -ISource -ISource/Metadata -ISource/FreeImageToolkit -ISource/LibJPEG -ISource/LibPNG -ISource/LibT
    IFF4 -ISource/ZLib -ISource/LibOpenJPEG -ISource/OpenEXR -ISource/OpenEXR/Half -ISource/OpenEXR/Iex -ISource/OpenEXR/Ilm
    Imf -ISource/OpenEXR/IlmThread -ISource/OpenEXR/Imath -ISource/OpenEXR/IexMath -ISource/LibRawLite -ISource/LibRawLite/d
    craw -ISource/LibRawLite/internal -ISource/LibRawLite/libraw -ISource/LibRawLite/src -ISource/LibWebP -ISource/LibJXR -I
    Source/LibJXR/common/include -ISource/LibJXR/image/sys -ISource/LibJXR/jxrgluelib -c Source/FreeImage/FreeImage.cpp -o S
    ource/FreeImage/FreeImage.o
    In file included from c:/mingw/i686-w64-mingw32/include/crtdefs.h:10:0,
    from c:/mingw/i686-w64-mingw32/include/wchar.h:9,
    from c:/mingw/i686-w64-mingw32/include/c++/cwchar:44,
    from c:/mingw/i686-w64-mingw32/include/c++/bits/postypes.h:40,
    from c:/mingw/i686-w64-mingw32/include/c++/bits/char_traits.h:40,
    from c:/mingw/i686-w64-mingw32/include/c++/string:40,
    from c:/mingw/i686-w64-mingw32/include/c++/stdexcept:39,
    from <command-line>:0:
    c:/mingw/i686-w64-mingw32/include/unknwnbase.h: In member function 'HRESULT IUnknown::QueryInterface(Q)':
    c:/mingw/i686-w64-mingw32/include/unknwnbase.h:74:29: error: '__mingw_uuidof' was not declared in this scope
    return QueryInterface(__uuidof(Q), (void
    )pp);
    ^
    c:/mingw/i686-w64-mingw32/include/unknwnbase.h:74:29: error: expected primary-expression before 'typeof'
    return QueryInterface(
    uuidof(Q), (void **)pp);
    ^
    c:/mingw/i686-w64-mingw32/include/unknwnbase.h: At global scope:
    c:/mingw/i686-w64-mingw32/include/unknwnbase.h:79:1: error: expected initializer before '<' token
    CRT_UUID_DECL(IUnknown, 0x00000000, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46)
    ^
    c:/mingw/i686-w64-mingw32/include/unknwnbase.h:79:1: error: expected initializer before '<' token
    CRT_UUID_DECL(IUnknown, 0x00000000, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46)
    ^
    c:/mingw/i686-w64-mingw32/include/unknwnbase.h:214:1: error: expected initializer before '<' token
    __CRT_UUID_DECL(AsyncIUnknown, 0x000e0000, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46)

     
  • Vladimir

    Vladimir - 2015-05-29

    Hello there.
    I have written a simple hello world program under Windows:

    #include <windows.h>

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
    MessageBox(NULL,"text","text", MB_OK);
    return 0;
    }

    It works fine when compiling it with MinGW (shows message box):
    g++ -c main.cpp
    g++ -o hello.exe main.o -mwindows

    But then I downloaded latest sources of FreeImage library, uncommented line in Makefile.mingw to let make it STATIC. Ran make. Then copied target library to my hello world project.
    Then I attached it to the linker:
    g++ -o hello.exe main.o libfreeimage.a -mwindows

    My program doesn't even show message box for now. Then I tried to link shared library and it worked fine.
    I think it's some kind of problem under MinGW when working with static library.
    Maybe I'm doing something wrong? Any suggestions?

    Vladimir

     

Log in to post a comment.