Jump to content

FreeImage build errors


Josh
 Share

Recommended Posts

I get these errors when building FreeImage on macOS:

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 % 

 

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Did you try this? Seems the only error is with LSEEK. The rest is Clang being annoying.

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

android - implicit declaration of function 'lseek64' is invalid in C99 - Stack Overflow

 

There is a similar issue with this repo, maybe the solution is the same?

Install failure on macOS 11.0.1 Homebrew python 3.9 on Intel Hardware · Issue #828 · PyTables/PyTables · GitHub

 

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

Changes:

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

This compiles the FreeImage library, but it is only building an Intel library, not a universal binary.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

-DPNG_ARM_NEON_OPT=0 must also be added to COMPILERFLAGS to prevent linking errors. :rolleyes:

I got universal binaries working as so:

COMPILERFLAGS_X86_64 = -arch x86_64 -arch arm64

Remove the -arch_only argument / parameter from the libtool command.

Remove the LIPO command.

Working makefile.osx:

# -*- Makefile -*-
# Mac OSX makefile for FreeImage

# This file can be generated by ./gensrclist.sh
include Makefile.srcs

# Find SDK path via xcode-select, backwards compatible with Xcode vers < 4.5
MACOSX_SYSROOT = $(shell xcrun --show-sdk-path)
# Specify deployement target here
MACOSX_DEPLOYMENT_TARGET = 10.11

# General configuration variables:
CC_I386 = $(shell xcrun -find clang)
CC_X86_64 = $(shell xcrun -find clang)
CPP_I386 = $(shell xcrun -find clang++)
CPP_X86_64 = $(shell xcrun -find clang++)
MACOSX_DEPLOY = -mmacosx-version-min=$(MACOSX_DEPLOYMENT_TARGET)
COMPILERFLAGS = -Os -fexceptions -fvisibility=hidden -DNO_LCMS -D__ANSI__ -DDISABLE_PERF_MEASUREMENT -DPNG_ARM_NEON_OPT=0
COMPILERFLAGS_I386 = -arch i386
COMPILERFLAGS_X86_64 = -arch x86_64 -arch arm64
COMPILERPPFLAGS = -Wno-ctor-dtor-privacy -D__ANSI__ -std=c++11 -stdlib=libc++ -Wc++11-narrowing
INCLUDE +=
INCLUDE_I386 = -isysroot $(MACOSX_SYSROOT)
INCLUDE_X86_64 = -isysroot $(MACOSX_SYSROOT)
CFLAGS_I386 = $(COMPILERFLAGS) $(COMPILERFLAGS_I386) $(INCLUDE) $(INCLUDE_I386) $(MACOSX_DEPLOY)
CFLAGS_X86_64 = $(COMPILERFLAGS) $(COMPILERFLAGS_X86_64) $(INCLUDE) $(INCLUDE_X86_64) $(MACOSX_DEPLOY)
CPPFLAGS_I386 = $(COMPILERPPFLAGS) $(CFLAGS_I386)
CPPFLAGS_X86_64 = $(COMPILERPPFLAGS) $(CFLAGS_X86_64)
LIBRARIES_I386 = $(MACOSX_DEPLOY) -Wl,-syslibroot $(MACOSX_SYSROOT)
LIBRARIES_X86_64 = $(MACOSX_DEPLOY) -Wl,-syslibroot $(MACOSX_SYSROOT)
LIBTOOL = libtool
LIPO = lipo

TARGET = freeimage
STATICLIB = lib$(TARGET).a
SHAREDLIB = lib$(TARGET)-$(VER_MAJOR).$(VER_MINOR).dylib
LIBNAME = lib$(TARGET).$(VER_MAJOR).dylib
HEADER = Source/FreeImage.h

.SUFFIXES: .o-i386 .o-x86_64
MODULES_I386 = $(SRCS:.c=.o-i386)
MODULES_X86_64 = $(SRCS:.c=.o-x86_64)
MODULES_I386 := $(MODULES_I386:.cpp=.o-i386)
MODULES_X86_64 := $(MODULES_X86_64:.cpp=.o-x86_64)

PREFIX = /usr/local
INSTALLDIR = $(PREFIX)/lib
INCDIR = $(PREFIX)/include

default: all

all: dist

# ONLY STATIC AND 64 BIT // START ---

dist: FreeImage
	cp *.a Dist
	cp Source/FreeImage.h Dist

FreeImage: $(STATICLIB)

$(STATICLIB): $(STATICLIB)-x86_64
	cp -p $(STATICLIB)-x86_64 $(STATICLIB)

# --- END

# STATIC AND DYNAMIC 32 and 64 BIT // START ---

#dist: FreeImage
#	cp *.a Dist
#	cp *.dylib Dist
#	cp Source/FreeImage.h Dist

# FreeImage: $(STATICLIB) $(SHAREDLIB )

#$(STATICLIB): $(STATICLIB)-i386 $(STATICLIB)-x86_64
#	$(LIPO) -create $(STATICLIB)-i386 $(STATICLIB)-x86_64 -output $(STATICLIB)

# --- END

$(STATICLIB)-i386: $(MODULES_I386)
	$(LIBTOOL) -arch_only i386 -o $@ $(MODULES_I386)

$(STATICLIB)-x86_64: $(MODULES_X86_64)
	$(LIBTOOL) -o $@ $(MODULES_X86_64)

#$(SHAREDLIB): $(SHAREDLIB)-i386 $(SHAREDLIB)-x86_64
#	$(LIPO) -create $(SHAREDLIB)-i386 $(SHAREDLIB)-x86_64 -output $(SHAREDLIB)

$(SHAREDLIB)-i386: $(MODULES_I386)
	$(CPP_I386) -arch i386 -dynamiclib $(LIBRARIES_I386) -o $@ $(MODULES_I386)

$(SHAREDLIB)-x86_64: $(MODULES_X86_64)
	$(CPP_X86_64) -arch x86_64 -arm arm64 -dynamiclib $(LIBRARIES_X86_64) -o $@ $(MODULES_X86_64)

.c.o-i386:
	$(CC_I386) $(CFLAGS_I386) -c $< -o $@

.c.o-x86_64:
	$(CC_X86_64) $(CFLAGS_X86_64) -c $< -o $@

.cpp.o-i386:
	$(CPP_I386) $(CPPFLAGS_I386) -c $< -o $@

.cpp.o-x86_64:
	$(CPP_X86_64) $(CPPFLAGS_X86_64) -c $< -o $@

install:
	install -d -m 755 -o root -g wheel $(INCDIR) $(INSTALLDIR)
	install -m 644 -o root -g wheel $(HEADER) $(INCDIR)
	install -m 644 -o root -g wheel $(SHAREDLIB) $(STATICLIB) $(INSTALLDIR)
	ranlib -sf $(INSTALLDIR)/$(STATICLIB)
	ln -sf $(SHAREDLIB) $(INSTALLDIR)/$(LIBNAME)

clean:
	rm -f core Dist/*.* u2dtmp* $(MODULES_I386) $(MODULES_X86_64) $(STATICLIB) $(STATICLIB)-i386 $(SHAREDLIB) $(SHAREDLIB)-i386 $(SHAREDLIB)-x86_64

 

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

The beta build is updated on Steam now, but I need to work out the build directory and working directory. It's difficult to change these things in Xcode, and he default locations are not good.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

  • 1 month later...
  • 8 months later...

Just realized you can't open patch @DereKC. Slight changes made to Makefile.osx

# -*- Makefile -*-
# Mac OSX makefile for FreeImage

# This file can be generated by ./gensrclist.sh
include Makefile.srcs

# Find SDK path via xcode-select, backwards compatible with Xcode vers < 4.5
MACOSX_SYSROOT = $(shell xcrun --show-sdk-path)
# Specify deployement target here
MACOSX_DEPLOYMENT_TARGET = 10.11

# General configuration variables:
CC_I386 = $(shell xcrun -find clang)
CC_X86_64 = $(shell xcrun -find clang)
CPP_I386 = $(shell xcrun -find clang++)
CPP_X86_64 = $(shell xcrun -find clang++)
MACOSX_DEPLOY = -mmacosx-version-min=$(MACOSX_DEPLOYMENT_TARGET)
COMPILERFLAGS = -Os -fexceptions -fvisibility=hidden -DNO_LCMS -D__ANSI__ -DDISABLE_PERF_MEASUREMENT -DPNG_ARM_NEON_OPT=0
COMPILERFLAGS_I386 = -arch i386
COMPILERFLAGS_X86_64 = -arch x86_64 -arch arm64
COMPILERPPFLAGS = -Wno-ctor-dtor-privacy -D__ANSI__ -std=c++11 -stdlib=libc++ -Wc++11-narrowing
INCLUDE +=
INCLUDE_I386 = -isysroot $(MACOSX_SYSROOT)
INCLUDE_X86_64 = -isysroot $(MACOSX_SYSROOT)
CFLAGS_I386 = $(COMPILERFLAGS) $(COMPILERFLAGS_I386) $(INCLUDE) $(INCLUDE_I386) $(MACOSX_DEPLOY)
CFLAGS_X86_64 = $(COMPILERFLAGS) $(COMPILERFLAGS_X86_64) $(INCLUDE) $(INCLUDE_X86_64) $(MACOSX_DEPLOY)
CPPFLAGS_I386 = $(COMPILERPPFLAGS) $(CFLAGS_I386)
CPPFLAGS_X86_64 = $(COMPILERPPFLAGS) $(CFLAGS_X86_64)
LIBRARIES_I386 = $(MACOSX_DEPLOY) -Wl,-syslibroot $(MACOSX_SYSROOT)
LIBRARIES_X86_64 = $(MACOSX_DEPLOY) -Wl,-syslibroot $(MACOSX_SYSROOT)
LIBTOOL = libtool
LIPO = lipo

TARGET = freeimage
STATICLIB = lib$(TARGET).a
SHAREDLIB = lib$(TARGET).$(VER_MAJOR).$(VER_MINOR).dylib
VERLIBNAME = lib$(TARGET).$(VER_MAJOR).dylib
LIBNAME = lib$(TARGET).dylib
HEADER = Source/FreeImage.h

.SUFFIXES: .o-i386 .o-x86_64
MODULES_I386 = $(SRCS:.c=.o-i386)
MODULES_X86_64 = $(SRCS:.c=.o-x86_64)
MODULES_I386 := $(MODULES_I386:.cpp=.o-i386)
MODULES_X86_64 := $(MODULES_X86_64:.cpp=.o-x86_64)

DESTDIR ?= /usr/local
INSTALLDIR ?= $(DESTDIR)/lib
INCDIR ?= $(DESTDIR)/include

default: all

all: dist

# ONLY STATIC AND DYNAMIC 64 BIT // START ---

dist: FreeImage
	cp *.a Dist
	cp *.dylib Dist
	cp Source/FreeImage.h Dist

$(STATICLIB): $(STATICLIB)-x86_64
	cp -p $(STATICLIB)-x86_64 $(STATICLIB)

# --- END

# STATIC AND DYNAMIC 32 and 64 BIT // START ---

#dist: FreeImage
#	cp *.a Dist
#	cp *.dylib Dist
#	cp Source/FreeImage.h Dist

FreeImage: $(STATICLIB) $(SHAREDLIB)

#$(STATICLIB): $(STATICLIB)-i386 $(STATICLIB)-x86_64
#	$(LIPO) -create $(STATICLIB)-i386 $(STATICLIB)-x86_64 -output $(STATICLIB)

# --- END

$(STATICLIB)-i386: $(MODULES_I386)
	$(LIBTOOL) -arch_only i386 -o $@ $(MODULES_I386)

$(STATICLIB)-x86_64: $(MODULES_X86_64)
	$(LIBTOOL) -o $@ $(MODULES_X86_64)

$(SHAREDLIB): $(SHAREDLIB)-x86_64
	$(LIPO) -create $(SHAREDLIB)-x86_64 -output $(SHAREDLIB)

$(SHAREDLIB)-i386: $(MODULES_I386)
	$(CPP_I386) -arch i386 -dynamiclib $(LIBRARIES_I386) -o $@ $(MODULES_I386)

$(SHAREDLIB)-x86_64: $(MODULES_X86_64)
	$(CPP_X86_64) -dynamiclib $(LIBRARIES_X86_64) -o $@ $(MODULES_X86_64)

.c.o-i386:
	$(CC_I386) $(CFLAGS_I386) -c $< -o $@

.c.o-x86_64:
	$(CC_X86_64) $(CFLAGS_X86_64) -c $< -o $@

.cpp.o-i386:
	$(CPP_I386) $(CPPFLAGS_I386) -c $< -o $@

.cpp.o-x86_64:
	$(CPP_X86_64) $(CPPFLAGS_X86_64) -c $< -o $@

install:
	install -d -m 755 -o $(USER) -g staff $(INCDIR) $(INSTALLDIR)
	install -m 644 -o $(USER) -g staff $(HEADER) $(INCDIR)
	install -m 644 -o $(USER) -g staff $(SHAREDLIB) $(STATICLIB) $(INSTALLDIR)
	ranlib -sf $(INSTALLDIR)/$(STATICLIB)
	ln -sf $(SHAREDLIB) $(INSTALLDIR)/$(VERLIBNAME)
	ln -sf $(SHAREDLIB) $(INSTALLDIR)/$(LIBNAME)

clean:
	rm -f core Dist/*.* u2dtmp* $(MODULES_I386) $(MODULES_X86_64) $(STATICLIB) $(STATICLIB)-i386 $(SHAREDLIB) $(SHAREDLIB)-i386 $(SHAREDLIB)-x86_64

 

Link to comment
Share on other sites

  • 1 year later...

Hi all, a bit late to the party here. Thanks for the patches! The provided Makefile.osx versions here seem to produce a universal binary static library and a ARM64 only shared library. I need to build a universal binary shared lib though. Is there anything that I am overlooking?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...