Objective C projects use the clang
compiler (you may still be using gcc), which is a (technically speaking) C
compiler, not a C++
compiler. It's smart enough to use file extensions to determine whether to compile code as C
, Objective C
or C++
.
When you link an Objective C project it links using clang
, which doesn't link in the C++
runtime. You need to link in the runtime.
If you're building your library using the libc++
library, then you will need to add libc++
to the list of libraries that are linked into the project in the Build Phases -> Link Binary With Libraries
. If you're building with the libstdc++
library, then you will need to add libstdc++
to the list of libraries that are linked in.
Xcode is smart enough to link using clang++
if there is even one C++
file in the project, eliminating your need to explicitly link in the C++
runtime in that situation.
tl;dr - it looks like you're not compiling the C++
code for the simulator with the same flags as you're building your main app. The line:
CXXFLAGS_SIM += $(EXTRA_CFLAGS_SIM) -fvisibility-inlines-hidden
is actually missing the base $(CXXFLAGS)
item and should read:
CXXFLAGS_SIM += $(CXXFLAGS) $(EXTRA_CFLAGS_SIM) -fvisibility-inlines-hidden
similarly for the CXXFLAGS_PHONE
line
as a result you're mixing libc++
and libstdc++
compiled code which leads to the link error. It should have been a hint that the CXXFLAGS
line was not being used as it has c++
at the start of the compile line, which would have triggered a compile error if it was used in any of the code.
There are other issues, e.g. to use libc++
your iPhone deployment target must be iOS 5 or later (so __IPHONE_OS_VERSION_MIN_REQUIRED=50000
is needed for the simulator compilation), and you'll need to fix up some of the files because of sign-extension issues e.g.
Source/LibRawLite/./internal/dcraw_common.cpp:3926:19: error: constant expression evaluates to 128 which cannot be narrowed to type 'signed char' [-Wc++11-narrowing]
If you want to check whether C++
code has been compiled with -stdlib=libc++
or -stdlib=libstdc++
, you can do an nm
of any of the resultant compiled code, passing it through c++filt
. If you see a namespace of std::__1::
, then the code was compiled with -stdlib=libc++
, otherwise it was compiled with -stdlib=libstdc++