Linking to SDL2_image fails on iOS

Hello there,

I am not able to link to the SDL2_image static library I have built for my project, but only when building for my iPhone. I am able to successfully build the project when using the iPhoneSimulator as the target.

Ld build/Debug-iphonesimulator/hello-sdl2-ios-cmake.app/hello-sdl2-ios-cmake normal i386
cd /Users/jeff/Projects/hello-sdl2-ios-cmake.git
export IPHONEOS_DEPLOYMENT_TARGET=7.1
export PATH="/Applications/Developer/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Developer/Xcode.app/Contents/Developer/usr/bin:/Users/jeff/.rbenv/shims:/Users/jeff/local/bin:/Users/jeff/.rbenv/versions/1.9.3-p0/bin:/Users/jeff/.rbenv/shims:/Users/jeff/Projects/nomdev.git:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/Users/jeff/Applications:/usr/X11/bin:/usr/local/gcc-4.8.0-qt-4.8.4-for-mingw32/win32-gcc/bin:/Users/jeff/local/bin/checker:/usr/local/texlive/2013basic/bin/x86_64-darwin"
/Applications/Developer/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch i386 -isysroot /Applications/Developer/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk -L/Users/jeff/Projects/hello-sdl2-ios-cmake.git/build/Debug-iphonesimulator -F/Users/jeff/Projects/hello-sdl2-ios-cmake.git/build/Debug-iphonesimulator -filelist /Users/jeff/Projects/hello-sdl2-ios-cmake.git/build/hello-sdl2-ios-cmake.build/Debug-iphonesimulator/hello-sdl2-ios-cmake.build/Objects-normal/i386/hello-sdl2-ios-cmake.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -framework Foundation -framework AudioToolbox -framework CoreGraphics -framework QuartzCore -framework ImageIO -framework UIKit -framework OpenGLES -Wl,-headerpad_max_install_names /Users/jeff/Projects/hello-sdl2-ios-cmake.git/third-party/ios/SDL2/libs/libSDL2.a /Users/jeff/Projects/hello-sdl2-ios-cmake.git/third-party/ios/SDL2_image/libs/libSDL2_image.a /Users/jeff/Projects/hello-sdl2-ios-cmake.git/third-party/ios/SDL2_ttf/libs/libSDL2_ttf.a -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=7.1 -Xlinker -dependency_info -Xlinker /Users/jeff/Projects/hello-sdl2-ios-cmake.git/build/hello-sdl2-ios-cmake.build/Debug-iphonesimulator/hello-sdl2-ios-cmake.build/Objects-normal/i386/hello-sdl2-ios-cmake_dependency_info.dat -o /Users/jeff/Projects/hello-sdl2-ios-cmake.git/build/Debug-iphonesimulator/hello-sdl2-ios-cmake.app/hello-sdl2-ios-cmake

Undefined symbols for architecture i386:
"_UTTypeConformsTo", referenced from:
_Internal_isType_ImageIO in libSDL2_image.a(IMG_ImageIO.o)
"_kUTTypeGIF", referenced from:
_IMG_isGIF in libSDL2_image.a(IMG_ImageIO.o)
_IMG_LoadGIF_RW in libSDL2_image.a(IMG_ImageIO.o)
"_kUTTypeJPEG", referenced from:
_IMG_isJPG in libSDL2_image.a(IMG_ImageIO.o)
_IMG_LoadJPG_RW in libSDL2_image.a(IMG_ImageIO.o)
"_kUTTypePNG", referenced from:
_IMG_isPNG in libSDL2_image.a(IMG_ImageIO.o)
_IMG_LoadPNG_RW in libSDL2_image.a(IMG_ImageIO.o)
"_kUTTypeTIFF", referenced from:
_IMG_isTIF in libSDL2_image.a(IMG_ImageIO.o)
_IMG_LoadTIF_RW in libSDL2_image.a(IMG_ImageIO.o)

…/third-party/ios/SDL2_image/libs/libSDL2_image.a: Mach-O universal binary with 4 architectures
…/third-party/ios/SDL2_image/libs/libSDL2_image.a (for architecture armv7): current ar archive random library
…/third-party/ios/SDL2_image/libs/libSDL2_image.a (for architecture armv7s): current ar archive random library
…/third-party/ios/SDL2_image/libs/libSDL2_image.a (for architecture i386): current ar archive random library
…/third-party/ios/SDL2_image/libs/libSDL2_image.a (for architecture cputype (16777228) cpusubtype (0)): current ar archive random library

Note that my SDL2_image.a is “universal”, and includes the i386 symbols.

How is it that I can build my project for the iPhoneSimulator (i386) but then not have the symbols when building for my iPhone? Thank you for any advice regarding these issues.

Cheers,
Jeffrey Carpenter
<@Jeffrey_Carpenter>

Did you compile the library for armv7 ? If you did you need to combine them
into a fat library using the lipo tools.

Yes, I built the library for the following archs: i386, armv7, armv7s and arm64. I then combined them using lipo.

Maybe I have missed a step somewhere?The precise commands I have used to generate the library are:

mkdir "${HOME}/Projects/hello-sdl2-ios-cmake.git/third-party/ios/SDL2_image/libs"
mkdir “${HOME}/Projects/hello-sdl2-ios-cmake.git/third-party/ios/SDL2_image/include”

arch = armv7, armv7s, arm64

xcodebuild -sdk iphoneos7.1 -configuration Debug -scheme libSDL_image BUILD_DIR="/private/tmp/SDL2_image"

arch = i386

xcodebuild -sdk iphonesimulator7.1 -configuration Debug -scheme libSDL_image -arch i386 BUILD_DIR="/private/tmp/SDL2_image"

Universal “fat” lib

lipo -create /private/tmp/SDL2_image/Debug-iphoneos/libSDL2_image.a /private/tmp/SDL2_image/Debug-iphonesimulator/libSDL2_image.a -output “${HOME}/Projects/hello-sdl2-ios-cmake.git/third-party/ios/SDL2_image/libs/libSDL2_image.a”

Headers

cp -av …/SDL_image.h “${HOME}/Projects/hello-sdl2-ios-cmake.git/third-party/ios/SDL2_image/include”

For whatever it is worth, SDL2 and SDL2_ttf compiled & linked without a hitch. Thanks!On 2014/03/ 27, at 14:30, Alexander Chaliovski wrote:

Did you compile the library for armv7 ? If you did you need to combine them into a fat library using the lipo tools.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Cheers,
Jeffrey Carpenter
<@Jeffrey_Carpenter>

Did you link your project to imageIO.framework ?

Oops, in my original post, I mentioned that I had successfully linked SDL2_image into my project only when using the iPhoneSimulator target. This is false, I am NOT able to link the library, on either targets.

The log messages I supplied remain the same across both iPhoneSimulator & my iPhone, differing only by “Undefined symbols for architecture i386” under simulator & “Undefined symbols for architecture armv7” under iPhone.

I’ve just discovered recently that when using the xcodebuild commands I attached in my previous message, I do get undefined symbol messages under both iphoneos and iphonesimulator SDKs.

iphoneos7.1

/Applications/Developer/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: for architecture: armv7 file: /Users/jeff/Library/Developer/Xcode/DerivedData/Build/Intermediates/SDL_image.build/Debug-iphoneos/libSDL_image.build/Objects-normal/armv7/libSDL2_image.a(IMG_gif.o) has no symbols
/Applications/Developer/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: for architecture: armv7 file: /Users/jeff/Library/Developer/Xcode/DerivedData/Build/Intermediates/SDL_image.build/Debug-iphoneos/libSDL_image.build/Objects-normal/armv7/libSDL2_image.a(IMG_jpg.o) has no symbols
/Applications/Developer/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: for architecture: armv7 file: /Users/jeff/Library/Developer/Xcode/DerivedData/Build/Intermediates/SDL_image.build/Debug-iphoneos/libSDL_image.build/Objects-normal/armv7/libSDL2_image.a(IMG_tga.o) has no symbols
/Applications/Developer/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: for architecture: armv7 file: /Users/jeff/Library/Developer/Xcode/DerivedData/Build/Intermediates/SDL_image.build/Debug-iphoneos/libSDL_image.build/Objects-normal/armv7/libSDL2_image.a(IMG_tif.o) has no symbols
/Applications/Developer/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: for architecture: armv7s file: /Users/jeff/Library/Developer/Xcode/DerivedData/Build/Intermediates/SDL_image.build/Debug-iphoneos/libSDL_image.build/Objects-normal/armv7s/libSDL2_image.a(IMG_gif.o) has no symbols
/Applications/Developer/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: for architecture: armv7s file: /Users/jeff/Library/Developer/Xcode/DerivedData/Build/Intermediates/SDL_image.build/Debug-iphoneos/libSDL_image.build/Objects-normal/armv7s/libSDL2_image.a(IMG_jpg.o) has no symbols
/Applications/Developer/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: for architecture: armv7s file: /Users/jeff/Library/Developer/Xcode/DerivedData/Build/Intermediates/SDL_image.build/Debug-iphoneos/libSDL_image.build/Objects-normal/armv7s/libSDL2_image.a(IMG_tga.o) has no symbols
/Applications/Developer/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: for architecture: armv7s file: /Users/jeff/Library/Developer/Xcode/DerivedData/Build/Intermediates/SDL_image.build/Debug-iphoneos/libSDL_image.build/Objects-normal/armv7s/libSDL2_image.a(IMG_tif.o) has no symbols

iphonesimulator7.1

/Applications/Developer/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: for architecture: i386 file: /Users/jeff/Library/Developer/Xcode/DerivedData/Build/Intermediates/SDL_image.build/Debug-iphonesimulator/libSDL_image.build/Objects-normal/i386/libSDL2_image.a(IMG_gif.o) has no symbols
/Applications/Developer/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: for architecture: i386 file: /Users/jeff/Library/Developer/Xcode/DerivedData/Build/Intermediates/SDL_image.build/Debug-iphonesimulator/libSDL_image.build/Objects-normal/i386/libSDL2_image.a(IMG_jpg.o) has no symbols
/Applications/Developer/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: for architecture: i386 file: /Users/jeff/Library/Developer/Xcode/DerivedData/Build/Intermediates/SDL_image.build/Debug-iphonesimulator/libSDL_image.build/Objects-normal/i386/libSDL2_image.a(IMG_tga.o) has no symbols
/Applications/Developer/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: for architecture: i386 file: /Users/jeff/Library/Developer/Xcode/DerivedData/Build/Intermediates/SDL_image.build/Debug-iphonesimulator/libSDL_image.build/Objects-normal/i386/libSDL2_image.a(IMG_tif.o) has no symbols
/Applications/Developer/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: for architecture: x86_64 file: /Users/jeff/Library/Developer/Xcode/DerivedData/Build/Intermediates/SDL_image.build/Debug-iphonesimulator/libSDL_image.build/Objects-normal/x86_64/libSDL2_image.a(IMG_gif.o) has no symbols
/Applications/Developer/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: for architecture: x86_64 file: /Users/jeff/Library/Developer/Xcode/DerivedData/Build/Intermediates/SDL_image.build/Debug-iphonesimulator/libSDL_image.build/Objects-normal/x86_64/libSDL2_image.a(IMG_jpg.o) has no symbols
/Applications/Developer/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: for architecture: x86_64 file: /Users/jeff/Library/Developer/Xcode/DerivedData/Build/Intermediates/SDL_image.build/Debug-iphonesimulator/libSDL_image.build/Objects-normal/x86_64/libSDL2_image.a(IMG_tga.o) has no symbols
/Applications/Developer/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: for architecture: x86_64 file: /Users/jeff/Library/Developer/Xcode/DerivedData/Build/Intermediates/SDL_image.build/Debug-iphonesimulator/libSDL_image.build/Objects-normal/x86_64/libSDL2_image.a(IMG_tif.o) has no symbols

So, I guess, my question becomes one of … what causes an otherwise successful build to have undefined symbols?

Thanks for any info, advice and what not you may be able to offer. I’m out of ideas to try -_-

Cheers,
Jeffrey Carpenter
<@Jeffrey_Carpenter>

Yes, I have. This inclusion fixed the initial bombardment of error messages of no symbols for ImageIO related code for my project.On 2014/03/ 27, at 17:20, Alexander Chaliovski wrote:

Did you link your project to imageIO.framework ?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Cheers,
Jeffrey Carpenter
<@Jeffrey_Carpenter>

You need to add those definitions when you compile SDL Image

-DLOAD_BMP -DLOAD_GIF -DLOAD_JPG -DLOAD_LBM -DLOAD_PCX -DLOAD_PNG
-DLOAD_PNM -DLOAD_TGA -DLOAD_TIF -DLOAD_XPM -DLOAD_XV

Awwe, I had hoped these were the missing flags for me, but no luck :frowning:

I had noticed a few moments before your e-mail arrived that the default project file did have those preprocessors included, but even when I explicitly added them under “Other C Flags”, this changed nothing for me.On 2014/03/ 27, at 17:27, Alexander Chaliovski wrote:

You need to add those definitions when you compile SDL Image

-DLOAD_BMP -DLOAD_GIF -DLOAD_JPG -DLOAD_LBM -DLOAD_PCX -DLOAD_PNG -DLOAD_PNM -DLOAD_TGA -DLOAD_TIF -DLOAD_XPM -DLOAD_XV


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Cheers,
Jeffrey Carpenter
<@Jeffrey_Carpenter>

They should be LDFLAGS not C Flags

When I swap from CFLAGS to LDFLAGS in either my project file or SDL2_image, I receive an error: “unknown option character ‘D’ in -DLOAD_BMP”.On 2014/03/ 27, at 17:43, Alexander Chaliovski wrote:

They should be LDFLAGS not C Flags


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Cheers,
Jeffrey Carpenter
<@Jeffrey_Carpenter>

I’m very happy to say that I was able to correct my linking to SDL2_image problem easily! I just needed to add MobileCoreServices to my project’s dependencies list.

Thank you for your help!

Cheers,
Jeffrey Carpenter
<@Jeffrey_Carpenter>