Adding a static library to an iPhone project - iphone

The motivation for this question is me trying to get LDAP functions to work with an iPhone application which is a project I'm attempting for part of my dissertation.
When I was developing the application I used the ldap.framework framework that is part of Mac OS X. This works fine in the simulator, but when I try to now get the app on a device it tells me that I'm not allowed to use this framework.
After some research I found that I could build openldap using the arm architecture and add the static library to my application destined for my device.
I eventually managed to compile configure and build openldap by setting variables as mentioned here and using the following commands...
Ade$ ./configure CC=$DEVROOT/usr/bin/arm-apple-darwin9-gcc-4.0.1 \
LD=$DEVROOT/usr/bin/ld --host=arm-apple-darwin --with-yielding_select=yes
Ade$ make depend
Ade$ make
I was told that the file I'm looking for will have an extension of '.a' so I searched for a '.a' file that mentions ldap...
Ade$ sudo find / -name *ldap*.a
Password:
/Users/Ade/Desktop/openldap-2.4.16/libraries/libldap/.libs/libldap.a
/Users/Ade/Desktop/openldap-2.4.16/libraries/libldap_r/.libs/libldap_r.a
So I assume these are the files I need?
My question is what do I do next? I know I need to add the library to the Xcode project and probably add a load of '.h' files too?
If anyone can give me a pointer to documentation or shed any light on the next stage I would be really grateful.
Many thanks,
Ade
ps. I have also talked about this process on my blog at www.greenpasta.com.

I've done this same thing to build an LDAP client for the iPhoneOS 2.2. You just to drag the .a into the "link with libraries" build stage. I recommend using the regular (non _r) version of the library, unless you specifically need reentrancy on your ldap stuff (which I don't recommend). You can also add the .h's to your project, which is generally the easiest way to access them.

Simply drag the .a files into the Xcode project and choose "copy files into project". I'm not familiar with OpenLDAP but I think the _r version is just a threadsafe version. I would recommend using that and not copying the other. You should probably not copy both files into Xcode or you will get link errors.
Then do the same for the .h files that define the client APIs of OpenLDAP - again I'm not sure which these are but I'm sure you can find out easily.
I would advise organising the .a and .h files together in a Xcode group under resources.
Include the header files in your source and you should be good to go.

You may also need to add -lldap to your linker command (in the build settings pane).

Related

This target might include its own product

File .../FaceDeFace.app depends on itself.
This target might include its own product.
File .../FaceDeFace.app depends on itself.
This target might include its own product.
I have done my project in os Snow leopard but now my os version also changed and it is now 10.7.3. This is installed in my Imac machine. This app start first in MacBook but now I want to develop it in IMac. But the above error is shown so what i have to do. Though I have change all of my certificate, and all provisioning profiles newly.
Please help.
Thanks i advance.
Select the target in your Xcode project and click the Build Phases tab. Look at the Target Dependencies list; the target's product should not be listed there, but it sounds like it may have been added to that list by mistake. Also check the other areas in that same tab -- you don't want your product listed in Copy Bundle Resources or Link Binary With Libraries, either -- you obviously can't use the thing that you're building as a resource or library to build the product in the first place. That's what Xcode seems to be complaining about.
Ran across this issue using Xcode 7 (beta 1) when trying to build a Static Library target. Here was the error message from the build output:
Unable to run command 'CopySwiftLibs libMyStaticLibraryName.a' - this target might include its own product.
(I substituted libMyStaticLibraryName.a above in place of the actual name of my static library.)
The problem turned out to be that this static library target had the Embedded Content Contains Swift Code build setting (EMBEDDED_CONTENT_CONTAINS_SWIFT) set to YES, when in reality there was no Swift code associated with this target. Setting this to NO in Xcode fixed the issue.
Static libraries cannot include Swift code, so if this build setting is set it causes the error, even if there is no actual Swift code in the target.
In my case, very simple, please delete Universal target, then add new target.
That's all
In my case my project had submodule inside, so commands
git submodule add submoduleURL
git submodule init
git submodule update
solved this issue.
I had the same problem, when podspec file was incorrect. My mistake was that I didn't specify .h and .m extensions for source_files. Because of that .xib files were added twice. This is a correct example:
s.source_files = 'YourTarget/Classes/**/*.{h,m}'
s.resources = ['YourTarget/Classes/UIComponents/**/*.xib']
See https://guides.cocoapods.org/syntax/podspec.html#source_files

Compile existing Lua app using XCode for iOS5

We had a freelance developer that went rogue and now I'm left with a Lua-based app with no build files.
I have a degree in computer science, but have no experience with Lua, so I'm wondering how I can compile this (or any Lua app) with XCode for iOS.
It's a fairly simple app. It appears as though it loads in images for navigation and displays other images as content.
How do I tell XCode to compile Lua for iOS though? I have all the files in XCode and it's compiling, but clearly its ignoring the .lua files and compiling the application shell.
I have Lua downloaded by source and also installed it via MacPorts. I read that I need to link lua.h and luac.h but I don't see how to add it as a build target.
Any advise or direction would be much appreciated.
These are the files I have:
Source Code/
build.settings
Clinical_Data/
page4a_2_Anim.lua
page4a_3_Anim.lua
page4a_4_Anim.lua
page4a_5_Anim.lua
page4b_2_Anim.lua
page4b_3_Anim.lua
page4b_4_Anim.lua
page4d_2_Anim.lua
page4d_3_Anim.lua
page4d_4_Anim.lua
config.lua
home.lua
Icon-72.png
images/
<*.png files>
main.lua
manifests/
CaseStudy.manifest.txt
ClinicalData.manifest.txt
Experience.manifest.txt
Home.manifest.txt
NavElements.manifest.txt
Pathology.manifest.txt
References.manifest.txt
Restasis.manifest.txt
menu.lua
page4a_2_Anim.lua
page4a_3_Anim.lua
page4a_4_Anim.lua
page4a_5_Anim.lua
page4b_2_Anim.lua
page4b_3_Anim.lua
page4b_4_Anim.lua
page4d_2_Anim.lua
page4d_3_Anim.lua
page4d_4_Anim.lua
parser.lua
pdfs/
<*.pdf files>
section.lua
slide.lua
slideView.lua
ui.lua
It's probably linking lua from your installed lua code. There'll be a -llua in your link code. Somewhere in your source files there'll be a
luaL_loadfile(L, file);
command. This loads the lua file.
If it's corona it might have a different way to load - haven't used it.
If you need an IDE http://www.eclipse.org/koneki/ldt/ is superb. You can remote debug your app very easily.
It looks like it may be corona from anscamobile.com.
You can download a trial version from their site to see if it compiles.

Help using iOSPorts to connect to an LDAP server

I am building an iPhone application which connects to an LDAP server (no encryption). I am trying to use iOSPorts but I am having trouble following the documentation, I think it was written for Xcode 3, while I've only ever used Xcode 4.
All that is required is to do simple search queries of the server and returning the results.
Some of the trouble I am having:
For example in step 3 my iOSPorts/include folder is empty and only contains the .gitignore file.
For step 4 which files do I need to add just the ports folder containing database, devel, iOSPorts and security?
For step 6 the direct dependencies panel, is this the target dependencies of build phases , which libraries need to be selected?
I think step 7 is for Xcode 3 too,
Any help with this would be much appreciated!
I am building an iPhone application which connects to an LDAP server (no encryption). I am trying to use iOSPorts but I am having trouble following the documentation, I think it was written for Xcode 3, while I've only ever used Xcode 4.
The original instructions were created for Xcode 3 since Xcode 4 was still in early beta when I published the first release of iOS Ports. The instructions have been updated within the last month for use with Xcode 4. I try to use the name used by "Xcode 4 User Guide" when describing the steps, so I recommend reading the first few chapters of this document from Apple.
For example in step 3 my iOSPorts/include folder is empty and only contains the .gitignore file.
Initially the include directory will be empty. The individual ports will copy the header files to the include directory. This is to prevent the end developer from needing to add a path to OpenSSL, Cyrus SASL, and OpenLDAP in order to compile an app for OpenLDAP.
Any help with this would be much appreciated!
So here is a quick run down of how iOS Ports works.
Each port of an Open Source package has an Xcode project file. That Xcode project file lists other Xcode project files and Makefiles as dependencies. Here is the high level steps used by an iOS Ports Xcode project file to compile the port:
Execute the port's MakeFile
Makefile: Download the source archive from the Internet (fails if Internet is unavailable)
Makefile: Verifies the integrity of the source archive using md5sum.
Makefile: Unpacks the source archive.
Makefile: Applies any required patches to the source code.
Makefile: Copies headers to the iOS Ports include directory.
Build any libraries from other ports listed in the build settings' Target Dependencies (for instance, libldap.a in OpenLDAP requires libsasl2.a from Cyrus SASL).
Compiles requested library.
The README has more information on how to add the project files to your project and link against the libraries. There also a few example programs in the examples directory.
If you do continue to have problems, please let me know. I try my best to keep on top of requests for help regarding iOS Ports and my other projects.
I haven't gone through all the process, but I am pretty sure for step 3, you have to 'make' the project first. There is a Makefile in the top folder of the project.

Developing with Qooxdoo and multiple developers

I'm interested in Qooxdoo as a possible web development framework. I have downloaded the SDK and installed it in a central location on my PC as I expect to use it on multiple projects. I used the create-application.py script to make a new test application and added all the generated files to my version control system.
I would like to be able to collaborate on this with other developers on other PCs. They are likely to have the SDK installed in a different location. The auto-generated files in Qooxdoo seem to include the SDK path in both config.json and generator.py: if the SDK path moves, the generator.py script stops working. generator.py doesn't seem to be too much of a problem as it looks in config.json for an updated path, but I'm not sure how best to handle config.json.
The only options I've thought of so far are:
Exclude it from the VCS, but there doesn't seem to be a script to regenerate it automatically, so this could be dangerous.
Add it to the VCS but have each developer modify the path line and accept that it might need to be adjusted whenever changes are merged.
Change config.json to be a path and a single 'include' line that points to a second file that contains all the non-SDK-path related information.
Use a relative path to the SDK and keep a separate, closely located copy of the SDK for every project that uses it.
Approach 1 would be ideal if the generation script existed; approach 2 is really nasty; I couldn't get approach 3 to work and approach 4 is a bit messy as it means multiple copies of the SDK littered about the place.
The Android SDK seems to deal with this very well (using approach 1), with the SDK path in its own file with a script that automatically generates that file. As far as I can tell, Qooxdoo puts lots of other important information in config.json and the only way to automatically generate that file is to create a new project.
Is there a better/recommended way to deal with this?
As an alternative to using symlinks, you can override the QOOXDOO_PATH macro on the command line:
./generate.py source -m QOOXDOO_PATH:<local_path_to_qooxdoo>
(Depending on the shell you are using you might have to apply some proper quoting of the -m argument). This way, every programmer can use his locally installed qooxdoo SDK. You can even drop the QOOXDOO_PATH entry from config.json to enforce this.
We work with a symbolic link pointing to the sdk ... config.json contains just the path of the link.

dyld: Library not loaded - When app run from the command line

I face some difficulties when adding a framework to my project when i run an iPhone app from the command line.
My final goal is to run applications tests from an automated build process.
When i run my app from xCode :
I add a "Copy File" build phase to my target and everything goes fine.
The copy is set to $(BUILT_PRODUCTS_DIR) as "Absolute path"
When i run my app from the terminal (using iphonesim project) i get this error :
dyld: Library not loaded: #rpath/OCMock.framework/Versions/A/OCMock
UIKitApplication:indemnisation[0xb894][26380] Referenced from: /Users/Admin/Library/Application Support/iPhone Simulator/User/Applications/CD5729B5-A674-49B2-91F6-AD398094B6F8/indemINT.app/indemINT
What i dont understand is that the copy build phase just copies the framework files in the same directory as the app.
When i run the app from the command line the framework files are already in the same directory. Does anyone knows why it doesn't work ?
I've also tried to add the OCMock.framework in the following directories (without success) :
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library
/Library/Frameworks
/Users/Admin/Library/Application Support/iPhone Simulator/User/Applications/CD5729B5-A674-49B2-91F6-AD398094B6F8
Thanks in advance,
Vincent.
I just had this same exact error in Xcode 4.2 (4D199) on Lion. I dragged/dropped the OCMock.framework folder into my project and selected the "copy files" checkbox. I saw the above answers and realized I neglected to add a "Copy Files" build phase to move the framework into place. I added one and dragged it right after the compile files build phase and tried to run my tests again. I couldn't get it to work until I had changed the destination in the "Copy Files" phase to the "Products Directory". Using "Frameworks" or "Shared Frameworks" did not work.
The iPhone does not support traditional Mac OS X frameworks. While the iPhone does use folders that end in ".framework", these folders are structured differently than typical Mac OS X frameworks. Most notably, iPhone frameworks are only permitted to use static libraries, while typical Mac OS X frameworks are dynamically loaded. That the message comes from dyld indicates that you are using a shared libary; however, applications targetting the iPhone may only be statically linked.
OCMock is distributed as a framework, and the iPhone does not allow you build your own arbitrary frameworks (there are good reasons to do this on a device with only 128MB of RAM and no swap).
The solution I see in a lot of places around the web is to put OCMock.framework in /Library/Frameworks or anywhere else in the standard framework search paths. This isn’t a very good solution: your build system is now dependent upon the state of your particular machine. Not good.
Another option would be to add the source for OCMock to your unit test target. This would work but is unnecessary, as your tests will never run on the iPhone,2 so why bother building them for ARM? Executables built for the iPhone simulator, being Mac OS X binaries, can link against dynamic libraries just fine. We can use this to our advantage.
What follows is what I believe is the best way to get OCMock working with iPhone projects:
First, add OCMock.framework to your project. Make sure that it’s being added to your Unit Tests target, not your application.
Next, add a Copy Files phase to your Unit Tests target. Set it up like so:
Destination :Absolute Path
Full Path :$(BUILT_PRODUCTS_DIR)
Now, drag OCMock.framework onto your new Copy Files phase to add it to the list of files to be copied.
Finally, drag the Copy Files phase, which I renamed it to “Copy OCMock”, between the Compile Sources and Link Binary With Libraries phases.
That’s it! Run (and by run I mean build) your tests and everything should work correctly.