I have a Foundation-based command-line utility that I'd like to add Realm support to. I can't use the Realm.framework, though, I don't have a bundle to add it to (and I prefer to avoid installation hacks that involve install_name_tool). It seems like I should be able to just build a static library (in lieu of the framework) and link my CLI utility against that.
I tried adding a static library target in the Realm Xcode project. This target is almost exactly the same as the OS X framework target (same source files, same link settings, but the type is Static library rather than Dynamic library). I link the static library against the core librealm.a library and it builds just fine. But, no matter how I build this thing, I get link errors when trying to link my CLI utility against the static library, e.g.:
Undefined symbols for architecture x86_64:
"std::runtime_error::what() const", referenced from:
vtable for realm::util::File::PermissionDenied in librealm_static.a(RLMRealm.o)
vtable for realm::util::File::AccessError in librealm_static.a(RLMRealm.o)
vtable for realm::RealmFileException in librealm_static.a(shared_realm.o)
vtable for realm::MismatchedConfigException in librealm_static.a(shared_realm.o)
vtable for realm::UnitializedRealmException in librealm_static.a(shared_realm.o)
vtable for realm::IncorrectThreadException in librealm_static.a(shared_realm.o)
vtable for realm::InvalidTransactionException in librealm_static.a(shared_realm.o)
...
"std::__1::error_code::message() const", referenced from:
realm::SharedGroup::do_open_2(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool, realm::SharedGroup::DurabilityLevel, bool, char const*) in librealm_static.a(group_shared.o)
realm::util::mmap(int, unsigned long, realm::util::File::AccessMode, unsigned long, char const*) in librealm_static.a(file_mapper.o)
(anonymous namespace)::mmap_anon(unsigned long) in librealm_static.a(file_mapper.o)
realm::util::munmap(void*, unsigned long) in librealm_static.a(file_mapper.o)
realm::util::mremap(int, unsigned long, void*, unsigned long, realm::util::File::AccessMode, unsigned long) in librealm_static.a(file_mapper.o)
realm::util::msync(void*, unsigned long) in librealm_static.a(file_mapper.o)
realm::util::make_dir(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in librealm_static.a(file.o)
...
[Edited to show undefined symbols when linking against librealm.a (vs. librealm-dbg.a)]
I have also tried using libtool to generate a combined static library of both the core librealm.a library and the static library generated from the open source components, e.g.:
cd "$TARGET_BUILD_DIR"
mv librealm_static.a librealm_dev.a
libtool -static -s -arch_only x86_64 -o librealm_static.a librealm_dev.a "$PROJECT_DIR"/core/librealm.a
Again, link errors when I link against the new "librealm_static.a" archive -- missing symbols.
Has anyone else successfully integrated Realm into an OS X command-line utility?