Menu

Compile Errors on Mac

Developers
josh
2021-07-11
2021-07-11
  • josh

    josh - 2021-07-11

    I am trying to compile FreeImage on macOS Catalina, with Xcode 12.2. The
    following errors occur:

    Last login: Sun Jul 11 13:47:54 on ttys000
    josh@Joshs-MacBook-Pro ~ % cd ~/Desktop/Freeimage
    josh@Joshs-MacBook-Pro Freeimage % make
    /Applications/Xcode.app/Contents/Developer/usr/bin/make -f Makefile.osx 
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -Os -fexceptions -fvisibility=hidden -DNO_LCMS -D__ANSI__ -arch x86_64 -I. -ISource -ISource/Metadata -ISource/FreeImageToolkit -ISource/LibJPEG -ISource/LibPNG -ISource/LibTIFF4 -ISource/ZLib -ISource/LibOpenJPEG -ISource/OpenEXR -ISource/OpenEXR/Half -ISource/OpenEXR/Iex -ISource/OpenEXR/IlmImf -ISource/OpenEXR/IlmThread -ISource/OpenEXR/Imath -ISource/OpenEXR/IexMath -ISource/LibRawLite -ISource/LibRawLite/dcraw -ISource/LibRawLite/internal -ISource/LibRawLite/libraw -ISource/LibRawLite/src -ISource/LibWebP -ISource/LibJXR -ISource/LibJXR/common/include -ISource/LibJXR/image/sys -ISource/LibJXR/jxrgluelib  -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -mmacosx-version-min=10.11 -c Source/ZLib/gzlib.c -o Source/ZLib/gzlib.o-x86_64
    Source/ZLib/gzlib.c:252:9: error: implicit declaration of function 'lseek' is
          invalid in C99 [-Werror,-Wimplicit-function-declaration]
            LSEEK(state->fd, 0, SEEK_END);  /* so gzoffset() is correct */
            ^
    Source/ZLib/gzlib.c:14:17: note: expanded from macro 'LSEEK'
    #  define LSEEK lseek
                    ^
    Source/ZLib/gzlib.c:252:9: note: did you mean 'fseek'?
    Source/ZLib/gzlib.c:14:17: note: expanded from macro 'LSEEK'
    #  define LSEEK lseek
                    ^
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdio.h:162:6: note: 
          'fseek' declared here
    int      fseek(FILE *, long, int);
             ^
    Source/ZLib/gzlib.c:258:24: error: implicit declaration of function 'lseek' is
          invalid in C99 [-Werror,-Wimplicit-function-declaration]
            state->start = LSEEK(state->fd, 0, SEEK_CUR);
                           ^
    Source/ZLib/gzlib.c:14:17: note: expanded from macro 'LSEEK'
    #  define LSEEK lseek
                    ^
    Source/ZLib/gzlib.c:359:9: error: implicit declaration of function 'lseek' is
          invalid in C99 [-Werror,-Wimplicit-function-declaration]
        if (LSEEK(state->fd, state->start, SEEK_SET) == -1)
            ^
    Source/ZLib/gzlib.c:14:17: note: expanded from macro 'LSEEK'
    #  define LSEEK lseek
                    ^
    Source/ZLib/gzlib.c:400:15: error: implicit declaration of function 'lseek' is
          invalid in C99 [-Werror,-Wimplicit-function-declaration]
            ret = LSEEK(state->fd, offset - state->x.have, SEEK_CUR);
                  ^
    Source/ZLib/gzlib.c:14:17: note: expanded from macro 'LSEEK'
    #  define LSEEK lseek
                    ^
    Source/ZLib/gzlib.c:496:14: error: implicit declaration of function 'lseek' is
          invalid in C99 [-Werror,-Wimplicit-function-declaration]
        offset = LSEEK(state->fd, 0, SEEK_CUR);
                 ^
    Source/ZLib/gzlib.c:14:17: note: expanded from macro 'LSEEK'
    #  define LSEEK lseek
                    ^
    5 errors generated.
    make[1]: *** [Source/ZLib/gzlib.o-x86_64] Error 1
    make: *** [default] Error 2
    josh@Joshs-MacBook-Pro Freeimage % 
    
     

    Last edit: josh 2021-07-11
  • josh

    josh - 2021-07-11

    These are the changes I made to make it compile successfully:

    Add at top of segdec.c:

    #ifdef __APPLE__
        #include <libkern/OSByteOrder.h>
        #define _byteswap_ulong(x) _OSSwapInt32
    #endif
    

    Add at top of gzguts.h:

    #ifdef __APPLE__
        #include <unistd.h>
    #endif
    

    Add at line 18 of gzlib.c:

    #ifdef __APPLE__
        #define _LARGEFILE64_SOURCE     /* See feature_test_macros(7) */
        #include <sys/types.h>
        #include <unistd.h>
    #endif
    

    Add at top of both copies of JXRGlueJxr.c:

    #ifdef __APPLE__
        #include <wchar.h>
    #endif
    
     

    Last edit: josh 2021-07-11

Log in to post a comment.