Search code examples
xcodecocoaattributesvisibilitydynamic-library

Xcode: How do I build my .app project also as a Shared Library?


First I am using Xcode 3.2.5 on a MAC OS X 10.6

I have an Cocoa Application project that builds and runs fine. I have some functions in this project that I am exporting out using:

#define CORE_EXPORT __attribute__ ((visibility ("default")))

extern "C" {
    CORE_EXPORT IUIEventHandler* GetIUIEventHandler();  
}

If I want another dynamic library project to be able to link to my original Cocoa Application so it can use the exported GetIUIEventHandler function, what do I need to do?

Do I need to build the original Cocoa Application also as a Dynamic Library also? Or is there a way to link the executable of the Cocoa Application?


Solution

  • This answer is kind of dirty but it works. I used the linker flag -undefined dynamic_lookup on my library that needs to import the functions from the main app executable, and I don't link in any library that holds the functions that need to be imported.

    This forces the linker to not worry undefined symbols and to mark them as should link at load time. When the app loads my library that was built with -undefined dynamic_lookup it will link up the undefined symbols itself.

    This is where I found my answer: http://lists.apple.com/archives/xcode-users/2008/Dec/msg00002.html