Using MMKVCore from C++ leads to undefined symbols
The language of MMKV
C++
The version of MMKV
2.1.1
The platform of MMKV
iOS (C++)
The installation of MMKV
CocoaPods (MMKVCore)
What's the issue?
I'm migrating react-native-mmkv to use the MMKV pod instead of building it from source.
I am working on it here: https://github.com/mrousavy/react-native-mmkv/pull/828
I updated all imports to use MMKVCore/MMKV.h, and fixed the namespace issues (those were ambiguous now), but when I try to build it I get undefined symbols for MMKV::initialize(...):
Undefined symbols for architecture arm64:
"mmkv::MMKV::initializeMMKV(std::1::basic_string<char, std::1::char_traits<char>, std::1::allocator<char>> const&, mmkv::MMKVLogLevel, void ()(mmkv::MMKVLogLevel, char const, int, char const, void))", referenced from:
facebook::react::NativeMmkvModule::initialize(facebook::jsi::Runtime&, std::1::basic_string<char, std::1::char_traits<char>, std::1::allocator<char>>) in libreact-native-mmkv.a[6](NativeMmkvModule.o)
ld: symbol(s) not found for architecture arm64
- My podfile:
react-native-mmkv.podspec - Call to the func that cannot be linked:
NativeMmkvModule.cpp(L31)
The other funcs (like getBoolean) seem to link fine. I don't see how initialize can fail, there's no conditional compilation here..?
Also, am I expected to compile C++ sources with -x -objective-c++ or is it fine as it is?
What's the log of MMKV when that happened?
Build error above
Hey, a quick reminder first. For your code to be compiled on both Android/iOS, you should handle the header differences between these platforms.
#ifdef __ANDROID__
#include <MMKV/MMKV.h>
#else
#include <MMKVCore/MMKV.h>
#endif
As for the handling of iOS/ObjC codes, you have two choices.
- Use the ObjC wrapper. In this case, the MMKVCore can be called both by C++ & ObjC. You should handle all .cpp file as
-x objective-c++. - Or, use the POSIX wrapper. In this case, the MMKVCore can only be called by C++. You should define the macro
FORCE_POSIX, and leave the .cpp file as is.
As for the undefined symbol issue, why don't you start small, create an iOS demo project that only uses the MMKVCore pods, calls mmkv::MMKV::initializeMMKV(), mmkv::MMKV::NameSpace() and stuff, then investigate from there?