1

我已经修改了 FreeImage 3.16.0 附带的 Makefile.osx 文件以使用 Clang 进行编译并使用最新的 10.8 Mac OS X SDK,它已经摆脱了大部分问题,但我完全被困在一个小问题上我找不到任何信息的链接器错误集。

我根据 stackoverflow 上其他帖子的建议修改了 makefile:如何在 Mac OS X 10.8 上编译 FreeImage?

这就是它目前的样子:

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

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

# General configuration variables:
CC_I386 = Clang
CC_X86_64 = Clang
CPP_I386 = Clang++
CPP_X86_64 = Clang++
COMPILERFLAGS = -Os -fexceptions -fvisibility=hidden -DNO_LCMS -D__ANSI__
COMPILERFLAGS_I386 = -arch i386
COMPILERFLAGS_X86_64 = -arch x86_64
COMPILERPPFLAGS = -Wno-ctor-dtor-privacy -D__ANSI__ -stdlib=libc++
INCLUDE += 
INCLUDE_I386 = -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk
INCLUDE_X86_64 = -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk
CFLAGS_I386 = $(COMPILERFLAGS) $(COMPILERFLAGS_I386) $(INCLUDE) $(INCLUDE_I386)
CFLAGS_X86_64 = $(COMPILERFLAGS) $(COMPILERFLAGS_X86_64) $(INCLUDE) $(INCLUDE_X86_64)
CPPFLAGS_I386 = $(COMPILERPPFLAGS) $(CFLAGS_I386)
CPPFLAGS_X86_64 = $(COMPILERPPFLAGS) $(CFLAGS_X86_64)
LIBRARIES_I386 = -Wl,-syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk
LIBRARIES_X86_64 = -Wl,-syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk
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

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)

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

$(STATICLIB)-x86_64: $(MODULES_X86_64)
    $(LIBTOOL) -arch_only x86_64 -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 -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

据我所知,我得到的链接器错误在 LibJXR 中:

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

我真的不知道该如何解决这个问题,特别是因为它只发生在 i386 配置中,x86_64 配置似乎链接得很好。

4

2 回答 2

3

如果您不需要 LibJXR 性能计时器,您可以禁用它们。在您的 makefile 中更改此行:

COMPILERFLAGS = -Os -fexceptions -fvisibility=hidden -DNO_LCMS -D__ANSI__

至:

COMPILERFLAGS = -Os -fexceptions -fvisibility=hidden -DNO_LCMS -D__ANSI__ -DDISABLE_PERF_MEASUREMENT
于 2014-04-07T22:05:28.877 回答
3

我还能够通过将文件“Source/LibJXR/image/sys/perfTimerANSI.c”添加到 Makefile.srcs 的 SRCS 部分来克服这些错误。那是实现列出为缺失的符号的文件。

于 2014-10-05T01:59:41.550 回答