Compiling libjpeg for iOS - objective-c

I am trying to compile a project for iOS 6 in XCode, and I am using the following headers, which include the functionality I need:
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#include "transupp.h" /* Support routines for jpegtran */
Those are straight out of jpegtran utility sources. I have installed the jpeg library before, and there is libjpeg.a in my /usr/local/lib/.
However when I try to compile, I am getting an error "Undefined symbols for architecture i386" or "Undefined symbols for architecture armv7", depending on whether target is an iPhone simulator or not.
Here are the keywords it can't find symbols for:
"_jpeg_stdio_src"
"_jpeg_finish_compress"
"_jcopy_markers_execute"
"_jpeg_copy_critical_parameters"
"_jtransform_adjust_parameters"
"_jpeg_destroy_compress"
"_jtransform_execute_transform"
"_jpeg_finish_decompress"
"_jpeg_read_header"
"_jtransform_request_workspace"
"_jpeg_write_coefficients"
"_jpeg_read_coefficients"
"_jpeg_destroy_decompress"
"_jpeg_stdio_dest"
"_jcopy_markers_setup"
I have encountered the missing symbol errors before, and always ended giving up on using 3rd party libraries, but in that particular case there's no way around.
What am I doing wrong here?
EDIT: I have added libjpeg.a to project settings and it did go further, but stopped now at:
Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
Target: i386-apple-darwin12.2.0
Thread model: posix
"lots-of-debug-paths"
ld: library not found for -ljpeg
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I recently needed libjpeg for iOS too (as a dependency of another third party library)
I ended up simply using the libjpeg-turbo, which comes with a precompiled fat binary
Architectures in the fat file: libjpeg.dylib are: i386 x86_64 armv6 armv7 armv7s arm64

I dunno how you compiled it. But you need to change the make install in order to compile it in i386 and armv7. I'm pretty sure you just run the make, so it compiled it for you mac, which is certainly a x84_64 arch, and this is certainly not what you want
You can check with
lipo -info /usr/local/lib/libjpeg.a // if libjpeg.a is at this path
or
file /usr/local/lib/libjpeg.a

Related

J2ObjC undefined symbols for architecture arm64

I'm trying to convert a java library to objective-c using j2objc and include the generated objc files into my XCode project. I managed to generate the objc files, but XCode gives me the following error: https://i.stack.imgur.com/QX3zF.png
I used lipo -info on a .o file and I get this "architecture: x86_64". Does it mean those objc files are not meant to run on arm64 architectures and if so, how can I solve this ? Are there any flags I could use to generate the files for arm64 ?
A previous error I had was "ARC forbids explicit message" and I solved this by adding a compiler flag -fno-objc-arc to all the compile sources related to this error. Is this solution safe ?
To compile for arm64, the -arch arm64 and -isysroot IPHONE_SDK_DIRECTORY flags are needed. To find the IPHONE_SDK_DIRECTORY on your system, run xcrun -sdk iphoneos --show-sdk-path.
There's nothing J2ObjC-specific about this, they are normal iOS flags you'll find in you look at the log of a successful compile of an Objective C file in Xcode and click its right button to expand and show all the flags used.
J2ObjC by default does not generate ARC code, so the -fno-objc-arc flag is okay. If you would prefer ARC, run j2objc with its -use-arc flag. Don't compile those generated files with -fno-objc-arc, however, as objects won't be released when your app is finished with them.

How to solve "Undefined symbols for architecture x86_64:"?

I've done hours and hours of searching and still no luck (read a lot of stackoverflow as well).
I am trying to implement FDTake via Cocoapods. When I try and run it I get the following:
undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_FDTakeController", referenced from:
objc-class-ref in VendeViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I know there is many similar questions around SO but all their solutions don't seem to work for me.
From the logs I can assume that you would be using a static library which is not build for simulator(architecture x86_64).
The library is only compiled for device and it needs to be complied and build for simulator also. Then the two static files (one abc.a for device and one abc.a for simulator) needs to be fat file i.e these files should be merged together using lipo command on terminal to create a fat file. Now when you use this fat file it will work both for simulator as well as device.
But the important thing is that you should have the source to compile and build the static libraries for simulator and device. After which you merge these to create a fat file which will work on all the defined architectures.
In case you are using third party static library (SDK) then you need to contact the respected party.

ImageIO linker error?

Trying to ready metadata (e.g kCGImagePropertyExifBodySerialNumber or kCGImagePropertyExifLensModel) from images using ImageIO framework.
Unfortunately during the compilation linker has a trouble:
Undefined symbols for architecture x86_64:
"_kCGImagePropertyExifBodySerialNumber", referenced from:
-[AppDelegate applicationDidFinishLaunching:] in AppDelegate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ImageIO/CGImageProperties.h is of corurse imported, and ImageIO.framework is included on the list "Linked Frameworks and Libraries" in target configuration.
It happends only when I'm trying to use kCGImagePropertyExifBodySerialNumber or kCGImagePropertyExifLensModel. It the same project kCGImagePropertyExifFocalLength, kCGImagePropertyExifExposureTime are used without any problems
Any ideas ?
Those constants seem to not be defined in the SDK versions of the ImageIO framework. You can check this yourself with the following command:
nm /Volumes/Applications/Developer\ Tools/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/ApplicationServices.framework/Frameworks/ImageIO.framework/imageio | grep -F kCGImagePropertyExifBodySerialNumber
(Edit the path to Xcode as appropriate.)
I'm on a Lion machine at the moment, and the system version of the same framework does have it:
% nm /System/Library/Frameworks/ApplicationServices.framework/Frameworks/ImageIO.framework/imageio | grep -F kCGImagePropertyExifBodySerialNumber
00000000000e4898 s _kCGImagePropertyExifBodySerialNumber
So, I suggest filing a bug and then, as a workaround, unsetting SDKROOT (“Base SDK”) in your project's build settings. With no SDK set, it should use the frameworks and headers of the system you're building on.
The downside of that workaround is that if you're using anything introduced on Mountain Lion, you won't be able to build on Lion.

IOS6 build link error

I build my app link with a static lib,found the errors follow
Undefined symbols for architecture armv7:
"std::_List_node_base::hook(std::_List_node_base*)", referenced from:
std::list<TSendBuf, std::allocator<TSendBuf> >::_M_insert(std::_List_iterator<TSendBuf>, TSendBuf const&) in libCardAnalyLib1.a(SendRecvThread.o)
"std::_List_node_base::unhook()", referenced from:
std::list<TSendBuf, std::allocator<TSendBuf> >::_M_erase(std::_List_iterator<TSendBuf>) in libCardAnalyLib1.a(SendRecvThread.o)
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Can anyone tell me what is this error? thank you.
And there is C++ code in the app and the lib.
my demo app can not link the lib, shows this error, and the TSendBuf is
typedef struct {
unsigned char szBuf[1200];//1000 fah char
} TSendBuf;
You probably need to add libstdc++.dylib to the list of frameworks/binaries your application links to.
You can do that from target settings / "Build Phases" tab / "Link binary with Libraries" section
Library and app possibly do not match in link-settings.
Check specifically for the the C++ Standard Library setting, under Apple LLVM compiler within the Xcode Build Settings of both, your library and your app. Those need to match.
Supposed that the library in question is nothing you are building yourself, and if that library was built some time ago (pre Xcode 4.5/LLVM 4.1), then the "correct" setting for your app would be libstdc++ (GNU C++ standard library).

Conditionally linking for #autoreleasepool

When I try to run my application in the iOS 4.3 simulator (Xcode 4.2), I crash when I hit #autoreleasepool{}, with:
dyld: lazy symbol binding failed: Symbol not found: _objc_autoreleasePoolPush
I looked around, and I see the workaround is to add libarclite_iphoneos.a. There's a version of this for the simulator, too, as libarclite_iphonesimulator.a.
I need to add both libraries to my project to make it run on both the simulator and hardware. But whichever I build, it complains that the other library is for an unsupported architecture.
For example, building for simulator:
ld: warning: ignoring file /Developer-4.2/Platforms/iPhoneOS.platform/
Developer/usr/lib/arc/libarclite_iphoneos.a, missing required architecture
i386 in file
How do I fix both of these simultaneously? Or should I just stick with the old NSAutoreleasePool syntax for now?
After a trials like clean, clean folder, resetting iPhone Simulator and even a restart, I changed the IPHONE_DEPLYMENT_TARGET on the target build setting down from iOS 5.0 to iOS 4.2.
Worked.
You can use the Other Linker Flags build setting to link in the library, and specialize the value based on whether it's "Any iOS" or "Any iOS Simulator".
You can also merge the two static libraries to one universal library. Go to the Terminal and say
lipo -create -output /where/you/want/it/libarclite_universal.a /Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/arc/libarclite_iphoneos.a /Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/arc/libarclite_iphonesimulator.a
You can verify the resulting file by saying (in Terminal)
file /where/you/put/it/libarclite_universal.a
It should output:
libarclite_universal.a: Mach-O universal binary with 3 architectures
libarclite_universal.a (for architecture i386):current ar archive random library
libarclite_universal.a (for architecture armv6):current ar archive random library
libarclite_universal.a (for architecture armv7):current ar archive random library
Since this lib is linked statically, your final app wont grow because of the included sim library since only whatever is needed by your app will get linked into your final app.