Change the protobuf library compiler option "Apple LLVM compiler 4.2 - Code Generation\Symbols Hidden by Default" to YES would solve this problem.
Strange EXC_BAD_ACCESS in iOS App
-
12-12-2021 - |
Question
I'm using MFMessageComposeViewController
to send message in my view controller. Before importing Google Protobuf Lib, all the things works. But after importing the lib, I always get a EXC_BAD_ACCESS error at the line of:
MFMessageComposeViewController *messager = [[MFMessageComposeViewController alloc] init];
But in the Debug Navigator, I always get the following stack, which leads me to bool SimpleDescriptorDatabase::DescriptorIndex<Value>::AddFile
method in descriptor_database.cpp
and then to bool InsertIfNotPresent
method in map-util.h
. Both descriptor_database.cpp
and map-util.h
are from Google Protobuf Lib
.
I'm confused why the initialization of MFMessageComposeViewController
has anything to do with Google Protobuf Lib
.
Removing the lib can solve the problem, but it's needed in my communication engine.
I've googled around, with no answer found. Thanks if anyone can lead me to the right direction.
I'm not sure if those two screenshots help:
Solution
OTHER TIPS
Compiling protobuf with gcc with the flag -fvisibility=hidden (without symbols) worked for me (compiled it for arm7)
This happened to me too. My stack trace wasn't exactly the same but similar.
From the trace it is apparent that calling [MFMessageComposeViewController init]
is causing libprotobuf.dylib to be loaded.
This is Apple's dylib, so MFMessageComposeViewController
either directly or indirectly relies on libprotobuf internally. Loading it is presumably clashing with your static version of protobuf.
I haven't figured out how/why this happens.
I worked around this issue by setting the C++ standard library to libc++. NOTE: You will also need to build all C++ libraries that you link to with libc++. When you build them make sure you set CXX=clang++
and CXXFLAGS='-stdlib=libc++
'.
NOTE: This will force you to target iOS 5.0+ as libc++ is not available on earlier versions of iOS.