I need to integrate a .dylib library and .h headers into iOS project to call its methods from Swift. It's illegal to add a .dylib file in iOS project, so I've tried to make a few workarounds:
Create a .xcframework with embedded .dylib and it's headers
Create a .framework with with embedded library binary, created using lipo command
Both workarounds compile successfully, but crashes when trying to run on a real device with message:
dyld[38413]: Library not loaded: #rpath/somelib.dylib
Referenced from: <6519D385-F3EB-3454-8CA0-02BF7E536629> /private/var/containers/Bundle/Application/D1A6139C-EC53-46DA-A647-4A520E4F112C/TestApp.app/TestApp
Reason: tried: '/usr/lib/system/introspection/somelib.dylib' (errno=2, not in dyld cache), '/private/var/containers/Bundle/Application/D1A6139C-EC53-46DA-A647-4A520E4F112C/TestApp.app/Frameworks/somelib.dylib' (errno=2), '/private/var/containers/Bundle/Application/D1A6139C-EC53-46DA-A647-4A520E4F112C/TestApp.app/Frameworks/somelib.dylib' (errno=2), '/private/preboot/Cryptexes/OS#rpath/somelib.dylib' (errno=2), '/private/var/containers/Bundle/Application/D1A6139C-EC53-46DA-A647-4A520E4F112C/TestApp.app/Frameworks/somelib.dylib' (errno=2), '/private/var/containers/Bundle/Application/D1A6139C-EC53-46DA-A647-4A520E4F112C/TestApp.app/Frameworks/somelib.dylib' (errno=2), '/usr/local/lib/somelib.dylib' (errno=2), '/usr/lib/somelib.dylib' (errno=2, not in dyld cache)
My guess is that some paths are setted up incorrectly, but I don't know how to fix that.
Here's content of my .h headers file:
#ifdef __cplusplus
extern "C" {
#endif
void ms_init(int width, int height);
void ms_draw();
#ifdef __cplusplus
}
#endif
I found a great answer to almost the same question, but the difference is that I use a .h headers.
Related
I am building the static iOS framework upon multiple libraries in Xcode. One of them should be the card.io. I cannot use cocoapods or carthage. So far I imported .frameworks within the .framework and it works pretty well. However card.io uses static library (.a file) with bunch of headers. It works well in dynamic type of .frameworks (or iOS app project) but in static project I get these errors on including of the .a files:
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -lCardIO
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -lCardIO is not an object file (not allowed in a library)
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -lopencv_core
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -lopencv_core is not an object file (not allowed in a library)
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -lopencv_imgproc
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -lopencv_imgproc is not an object file (not allowed in a library)
Regarding these errors I downloaded the source codes of card.io and it looks that there is dynamic .framework target waiting for build. I tried to use this one instead of .a files and headers - so my project at least can be builded. Because the card.io does not contatin architectures for simulator (which, by the way, it should with this release 5.2.2) I am not able to test it in unit tests, so when I test this solution on device I get this error:
dyld: Library not loaded: #rpath/CardIO.framework/CardIO
Referenced from: /var/containers/Bundle/Application/55D3AF7F-83F4-4B3D-A667-0FCO93CCC441/App/AppDemo
Reason: no suitable image found.
So far my knowledge+google+stackoverflow is stuck here, because it looks that xcode does not support the .framework within .framework this way.
To this moment I spent two days with this "issue", so the question is: Does exist any solution for including dynamic library into static framework? Or any solution to include card.io into static framework?
EDIT:
Well actually the solution was more stupid than I would think (as always). Just to include card.io in the .framework go to "Project Description -> Build Settings -> Library search paths" and type the path where should xcode look for the libraries. This approach solves the first one issue of this post - this means the implementation of the .a libraries and headers.
At this moment I cannot guarantee it will work in releases based on my framework so I will update this post to confirm it later. I hope it helps someone...
I'm using iOS Universal framework
template.
I created framework and added them as sub project to another project.
And added framework binaries to the project.
in my framework there is some constants
const float kToolbarHeight = 45;
And when i'm trying to Build my Project and included Framework for
iphone simulator (i386), there are linker errors:
ld: 14 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
but when i build it for device - there is not any linker errors.
I'm tried to exclude subProject (my framework) from Project, and and keep only binaries, but there is not any effect.
I'm trying to change architectures in targets to the i386, and to the $(VALID_ARCHS), as
described in that issue, but there is not any effect.
How can I build framework for iOS simulator, what settings of target should I use?
Update: The problem was resolved when I defined
my constants as extern in header file.
// MyView.h
extern const float kToolbarHeight;
// MyView.m
const float kToolbarHeight = 45;
But why? What difference in simulator and arm builds?
The problem was resolved when I defined my constants as extern in header file.
// MyView.h
extern const float kToolbarHeight;
// MyView.m
const float kToolbarHeight = 45;
about extern
I'm using ffplay in my Application. I implemented the Librarys which has been used in this Project: http://code.google.com/p/ffmpeg4iphone/downloads/detail?name=ffplay-xproj.zip&can=2&q=
But I've seen that this Sources are very old(Apr 2009). I wanted to Build new Librarys and then change it with these In my project.
What I've done:
Downloaded the ffmpeg Source code: (using command line: svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg)
Compiled the Project with special ./configure options and the gas-processor :
http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2009-October/076618.html
I only changed here the Paths of the actual locations for the iPhone SDK 4.1
Changed the header Path in xCode Active Target Project Settings to my ffmpeg folder
Included the .a files in my project in xCode
Added the Other Linker Flags -lm -lbz2 -lz
Tried to Build my Application, but I get some Linker errors where symbol(s) wasn't found.
Undefined symbols:
"avcodec_init()", referenced from:
And the other errors are nearly the same (_av_codec.....)
How can I build it correctly?
I've found the solution: I set the architecture to Optimized(arm7) and then all was working.
One more Question: I use ffmpeg for streaming an online stream. Which Values Should I set to get a good streaming quality also when I am in 3G. This what i've done:
set the audio-buffer to 1024
set the lowres value of mpeg to 3
Not sure if you are using C or C++ (g++) compiler, but try guarding your #includes for ffmpeg with extern "C": the c++ compiler (if it is used) is probably mangling the function names and hence the link errors.
Try to enclose your include with extern "C":
#ifdef __cplusplus
extern "C" {
#endif
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#ifdef __cplusplus
}
#endif
I downloaded OpenFeint version 2.3.1, unzipped and placed the OpenFeint folder inside right underneath my project in Xcode, and checked "recursively create groups if needed" (the instructions said to use groups and not a folder reference).
I renamed my AppViewController and AppDelegate .m files to .mm. I followed the rest of the instructions and compiled and ran, the app works fine.
Inside AppViewController.mm I do:
#import "OpeinFeint.h"
and compile, which gives me the errors:
#error: "OpenFeint requires Objective-C++. In Xcode, you can enable this by changing your file's extension to .mm".
#error: syntax error before 'OfNotificationCategory'
#error: syntax error before 'OfNotificationCategory'
and the location of the errors takes me to the OpenFeint files.
I did add -ObjC to Other Linker Flags and check Call C++ Default Ctors/Dtors in Objective-C.
Any advice? Thanks!
The linker flag should be -lobjc, not -ObjC.
The following code crashes in an Xcode created template project.
int main(int argc, char *argv[])
{
uint64_t t64 = 100000;
double s = (double)t64; // Crash!
...
The crash is accompanied with the following console output and occurs on a 2.2.1 device but not on 3.0.1 devices. It occurs both compiling for Thumb or ARM.
dyld: lazy symbol binding failed: Symbol not found: ___floatundidf
Referenced from: /var/mobile/Applications/15E9DC65-324D-4C3A-8477-DC8CFFA67DC1/MyApp.app/MyApp
Expected in: /usr/lib/libgcc_s.1.dylib
dyld: Symbol not found: ___floatundidf
Referenced from: /var/mobile/Applications/15E9DC65-324D-4C3A-8477-DC8CFFA67DC1/MyApp.app/MyApp
Expected in: /usr/lib/libgcc_s.1.dylib
The problem only occurs with a Base SDK of 3.0, compiling for 2.2.1 is fine. Unfortunately I have 3.0 enhancements.
When you say it works on one iPhone project and not another, are you compiling the same code with different settings? If so I'd check to see what settings differ between the two to shed light on what might be at the root of the problem.
___floatundidf should be part of libgcc so it might be missing in the ARM version of that libary for the 2.2.1 SDK but present in 3.0.1 (hence the crash in the former but not the latter). You can use the nm tool to check for its existence in both. If it is missing from 2.2.1 you should file a bug with Apple.
It works if you do. Weird
int main(int argc, char *argv[]) {
uint64_t t64 = 100000;
double s = (double)(uint64_t)t64; // Crash!
...