FreeImage is a very good library that supports many image formats.
When writing a cross-platform rendering engine, it is a very good choice if you do not want to rely on the API of each platform.
But on macOS, what we download here is the latest version FreeImage3180.zip on SourceForge
If you don't like brew download, download and compile yourself, you will encounter some problems. The first is a C99 bug.
Here, some developers in brew have responded to this problem a long time ago and submitted a patch. We only need
Download these patches, patch them yourself, and compile them.
source/zlib/gzlib.c:252:9: error: implicit declaration of function 'lseek' is invalid in c99
How to fix this error on mac?
First you have to download the patch. patch-c99-fixes.diff.txt
--- Source/LibJXR/image/sys/strcodec.c.orig 2015-02-21 04:36:26.000000000 +0000
+++ Source/LibJXR/image/sys/strcodec.c 2020-12-09 12:11:53.000000000 +0000
@@ -664,24 +664,6 @@
//================================================================
// Memory access functions
//================================================================
-#if (defined(WIN32) && !defined(UNDER_CE) && (!defined(__MINGW32__) || defined(__MINGW64_TOOLCHAIN__))) || (defined(UNDER_CE) && defined(_ARM_))
-// WinCE ARM and Desktop x86
-#else
-// other platform
-#ifdef _BIG__ENDIAN_
-#define _byteswap_ulong(x) (x)
-#else // _BIG__ENDIAN_
-U32 _byteswap_ulong(U32 bits)
-{
- U32 r = (bits & 0xffu) << 24;
- r |= (bits << 8) & 0xff0000u;
- r |= ((bits >> 8) & 0xff00u);
- r |= ((bits >> 24) & 0xffu);
-
- return r;
-}
-#endif // _BIG__ENDIAN_
-#endif
U32 load4BE(void* pv)
{
--- Source/LibJXR/image/sys/strcodec.h.orig 2015-02-21 04:35:46.000000000 +0000
+++ Source/LibJXR/image/sys/strcodec.h 2020-12-09 12:28:41.000000000 +0000
@@ -28,6 +28,7 @@
#pragma once
#include <stddef.h>
+#include <stdlib.h>
#if defined(__MINGW32__)
#include <stdint.h>
#endif
@@ -117,6 +118,25 @@
#define TraceResult(a)
+#if (defined(WIN32) && !defined(UNDER_CE) && (!defined(__MINGW32__) || defined(__MINGW64_TOOLCHAIN__))) || (defined(UNDER_CE) && defined(_ARM_))
+// WinCE ARM and Desktop x86
+#else
+// other platform
+#ifdef _BIG__ENDIAN_
+#define _byteswap_ulong(x) (x)
+#else // _BIG__ENDIAN_
+inline U32 _byteswap_ulong(U32 bits)
+{
+ U32 r = (bits & 0xffu) << 24;
+ r |= (bits << 8) & 0xff0000u;
+ r |= ((bits >> 8) & 0xff00u);
+ r |= ((bits >> 24) & 0xffu);
+
+ return r;
+}
+#endif // _BIG__ENDIAN_
+#endif
+
//================================================================
typedef enum tagPacketType
{
--- Source/LibJXR/jxrgluelib/JXRGlueJxr.c.orig 2013-12-06 23:04:54.000000000 +0000
+++ Source/LibJXR/jxrgluelib/JXRGlueJxr.c 2020-12-09 12:14:48.000000000 +0000
@@ -27,6 +27,7 @@
//
//*@@@---@@@@******************************************************************
#include <limits.h>
+#include <wchar.h>
#include <JXRGlue.h>
--- Source/ZLib/gzguts.h.orig 2017-01-01 20:37:10.000000000 +0000
+++ Source/ZLib/gzguts.h 2020-12-09 12:19:37.000000000 +0000
@@ -19,6 +19,8 @@
#endif
#include <stdio.h>
+#include <sys/types.h>
+#include <unistd.h>
#include "zlib.h"
#ifdef STDC
# include <string.h>
Then enter the code folder of FreeImage and apply the patch. Then start compiling.
patch -p0 < patch-c99-fixes.diff.txt
make -f Makefile.osx -j8
After the compilation is successful, libfreeimage.a will be generated, and then a FreeImage.h file will be added to form a library.
Then you can use it in XCode. But it's not over yet, there will be problems again during the linking phase.
Undefined symbols for architecture i386:
"_PerfTimerCopyStartTime", referenced from:
_ImageStrDecInit in strdec.o-i386
_ImageStrEncInit in strenc.o-i386
"_PerfTimerDelete", referenced from:
_ImageStrDecTerm in strdec.o-i386
_ImageStrEncTerm in strenc.o-i386
"_PerfTimerGetResults", referenced from:
_OutputIndivPerfTimer in strcodec.o-i386
"_PerfTimerNew", referenced from:
_ImageStrDecInit in strdec.o-i386
_ImageStrEncInit in strenc.o-i386
"_PerfTimerStart", referenced from:
_ImageStrDecInit in strdec.o-i386
_ImageStrDecDecode in strdec.o-i386
_ImageStrDecTerm in strdec.o-i386
_ImageStrEncInit in strenc.o-i386
_ImageStrEncEncode in strenc.o-i386
_ImageStrEncTerm in strenc.o-i386
_readIS in strcodec.o-i386
...
"_PerfTimerStop", referenced from:
_ImageStrDecInit in strdec.o-i386
_ImageStrDecDecode in strdec.o-i386
_ImageStrDecTerm in strdec.o-i386
_ImageStrEncInit in strenc.o-i386
_ImageStrEncEncode in strenc.o-i386
_ImageStrEncTerm in strenc.o-i386
_readIS in strcodec.o-i386
Here you only need to add "Source/LibJXR/image/sys/perfTimerANSI.c" to the SRCS section of Makefile.srcs
That's it. Students who don't want to toss by themselves can download directly here, source code + library. Help me contribute points.
The version available on FreeImage3.18macOS. -C++ Documentation Resources-CSDN Download