Linking Static Libraries in Xcode - xcode

I am trying to link the opengl image loading library Soil to my Xcode project, but I am finding this very difficult. I have tried to link the .a file but this does not work.
Any ideas?
Thanks

It looks like the supplied .a file isn't for Mac; you can instead make a new Xcode (BSD C library) project, include the source+ headers, and use this in a larger project.
If you're using Xcode 4, this link will help with the general approach to using / creating your own static libraries, and using them.

Related

Add dynamic library to firebreath

I'm developing a plugin for mac. I'm trying to use afnetworking and other frameworks which needs arc. I'm trying to create a .a(library) for the framework and access it in firebreath. I tried adding the directory which contains .a using include_directories in projectdef.cmake then linking it in target_link_libraries. Please lemme know how to add this and whether the framework can be used in firebreath without any pitfalls
I have used external libraries in firebreath. Though I have used editors to link the libraries. You need to specify .h files for the function prototypes, along with .a files which will dynamically link to .dylib
Try adding these via Xcode and see if that works.

How do I call unmanaged functions in C from Unity3d if I don't have a .bundle? (Mac)

I am on Mac.
I have a bunch of C source code (.c and .h).
I have a static library (.a).
I want to use that .a library from within Unity.
I looked into Unity's documentation for plug-ins (http://unity3d.com/support/documentation/Manual/Plugins.html), which says for PC and Mac stand alones, .bundle files seem to be the only solution. All example plugin-in projects that Unity give have .bundle plugins.
But I have seen prime31 plugins using .a library in Unity!
Anyone has a clue how they did that?
Here is all that I can tell from analyzing prime31 plugin:
(1) they put their .a library in Unity's Editor folder
(2) they have a C# script which contains lots of [DllImport ("__Internal")]
I tried to do the same:
(1) I wrote a simple hello_world.c in Xcode and built a .a library. I put the libhelloworld.a in Asset/Editor
(2) I then wrote a C# script that looks like this:
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
public class testlib : MonoBehaviour {
[DllImport ("libhelloworld")]
static public extern System.String helloworld();
}
(3) Then I wrote a test script:
using UnityEngine;
using System.Collections;
public class test : MonoBehaviour {
// Use this for initialization
void Start () {
print(testlib.helloworld());
}
}
(4) By doing so I get a runtime error:
DllNotFoundException: libhelloworld
test.Start () (at Assets/Script/test.cs:8)
Many, many thanks!
PS: In case some of you wonder why I have the source code but not the bundle. I am trying to build a bundle from those .c and .h but hasn't succeeded yet. The source code was compiled with make tools, but I don't know anything else that could build a bundle except for Xcode. So I guess I have to use Xcode to build my bundle. My problem is when I tried to build it with Xcode I get millions of errors saying that I have duplicate main entries. I checked the source code and found that it does have duplicate main()s because the source code has lots of utilities that come with it. I tried deleting those utilities but the same error doesn't go away...
I am planning to ask this question somewhere else because this does not seem very Unity-related. But if someone here happens to know the answer, please don't hesitate -- let me know!
Okay I got an email from the prime31 people. It's impossible to do that.
Unity does not build an Xcode project for OSX, so you can't link a static library. Unity does build an Xcode project for iOS, that's how the prime31 developers could use the .a library(in Xcode, not in Unity)
To sum up, to use unmanaged code in Unity on MacOS, the only correct way is to build a bundle from your source code and then import it to Unity. Just like their documentation said!
I think I will try to build a bundle from source code or try to build a bundle from the .a library that I am now able to build, though Mac OS documentation says it's pointless:
Note: Some Xcode targets (such as shell tools and static libraries) do
not result in the creation of a bundle or package. This is normal and
there is no need to create bundles specifically for these target
types. The resulting binaries generated for those targets are intended
to be used as is.
I may post another question and if that question got answered, I will include a link here...
Alright I am coming back to edit:
Finally I built a bundle from a .a static library and was able to call functions of the library from Unity. Here is how I did: How to organize C source file previously compiled by GCC Make and build them into an Xcode bundle? I have a Duplicate Symbol _main Error
I am using my own library for an iOS project and it works fine. I don't use Unity3D's mechanism of copying from plugins folder but set it up completely in XCode. In the above HelloWorld example try [DllImport("__Internal")].
Follow the links in my previous answer How to use an xcode game on unity3d look at my blog posting, it deals exactly with this problem.

How do I add a library compiled in XCode into Monotouch so that it works for both simulator and device?

There are appear to be methods of creating a fat static library ala "http://stackoverflow.com/questions/3520977/build-fat-static-library-device-simulator-using-xcode-and-sdk-4". Is this recommended? Any special steps (i.e., disabling thumb)
Also, if I do use the fat static library, will monotouch/xcode clear out any unused code in the final product?
You definitely need to turn Thumb code off so you can link properly against the library. As far as creating the fat static library goes, I can only say that anecdotally I've done this for a few third-party libraries that I've used and haven't run into issues.
I assume you already know that you need to create the bindings necessary to make calls to the objective-c library from your MonoTouch code and add extra gcc flags in the project properties to link in the static lib. If not, you can get that information on how to do that from the MonoTouch website.

Creating a library (.a) in Mac OS X and Xcode

I'm in the process of porting some code from Linux to Mac OS X. The code is a static library that you add to your code. Basically after you compile the code you get a MyLib.a that can be linked to whatever project you want.
I'm managing the "project" via a Makefile.
Is there a way to have a project on Xcode that ultimately produces the same kind of library? How?
Thank you for the help.
Sure. You don't say so, but I am assuming you are using C or C++ as source.
Assuming you are using Xcode 3.2.2, you can create a new project (File > New Project...), which will bring up a New Project window with available project templates. Select the "Framework & Library" category under Mac OSX from the list on the left. You should now see a "BSD C Library" and "STL C++ Library" among the other library and framework types. For building a static library like you described you want the "BSD C Library" option. There are static and dynamic options for this which you will see when you click on the icon, but static is default.
Depending on which version of Xcode you are using, the location of the project template may be a little different since Apple has been changing this UI for the New Project window fairly frequently. So if you are not using 3.2.2 you may need to poke around the available projects a little bit.
Oh, and don't worry if you are trying to build C++. Event though this says it is for C, C++ libs build just fine as well.

Share an Xcode project as a static library for other people to use in emulator. How do you use an AppDelegate from a .a static library file in Xcode?

I want to share my Xcode project as a static library for other people to use in the xcode emulator (giving them as little raw source code as possible). How do you use an AppDelegate from a .a library file in Xcode or UIBuilder?
I copied the main Window.xib file to a new project and included all of the other source files in a static .a library that I thought I would be able to invoke somehow. What do I have to do to launch my main product that is compiled into the .a library from a brand new Xcode project that is including that library?
You'll have to link to the static library. Include it in your new Xcode project, and then in the target for the application, go to the General tab and set the library as linked. You'll probably want to copy it into your new project's bundle (in the Frameworks directory), using a Copy Files build phase. You'll also need to reference the header files for the static library for avoid warnings.
This is a much better solution found in someone else's question:
iOS Question. Can I distribute the Xcode simulator versions of my app?

Resources