OpenGL レンダリング エンジンによって開発された FreeImage macOS での C99 コンパイル エラー

FreeImage は、多くの画像形式をサポートする非常に優れたライブラリです。

クロスプラットフォームのレンダリング エンジンを作成する場合、各プラットフォームの API に依存したくない場合は、これは非常に良い選択です。

ただし、macOS では、ここでダウンロードするのは SourceForge の最新バージョン FreeImage3180.zip です。

brew のダウンロードが好きではなく、自分でダウンロードしてコンパイルする場合は、いくつかの問題が発生します。1 つ目は C99 のバグです。

ここで、brew の一部の開発者はずっと前にこの問題に対応し、パッチを提出しました。

これらのパッチをダウンロードし、自分でパッチを適用してコンパイルします。

source/zlib/gzlib.c:252:9: エラー: 関数 'lseek' の暗黙的な宣言は c99 では無効です

Mac でこのエラーを修正するにはどうすればよいですか?

まずパッチをダウンロードする必要があります。パッチ-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>

次に、FreeImage のコード フォルダーに入り、パッチを適用します。次にコンパイルを開始します。

patch -p0 < patch-c99-fixes.diff.txt

make -f Makefile.osx -j8

コンパイルが成功すると、libfreeimage.a が生成され、FreeImage.h ファイルが追加されてライブラリが形成されます。

その後、それを XCode で使用できるようになります。しかし、まだ終わったわけではありません。リンク段階で再び問題が発生します。

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

ここでは、Makefile.srcs の SRCS セクションに「Source/LibJXR/image/sys/perfTimerANSI.c」を追加するだけです。

それでおしまい。自分で投げたくない学生は、ここからソースコードとライブラリを直接ダウンロードできます。ポイントの貢献にご協力ください。

FreeImage3.18macOS で利用可能なバージョン。-C++ ドキュメント リソース-CSDN ダウンロード

おすすめ

転載: blog.csdn.net/chenchao_shenzhen/article/details/124673105