Building Cocoa touch framework with c++11 code - ios

I am trying to make an iOS framework. My code includes c++11 features.
When I build the framework target I get errors such as:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ctime:56:9: No member named 'clock_t' in the global namespace
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ctime:58:9: No member named 'time_t' in the global namespace; did you mean 'size_t'?
How can I resolve this? Thanks.
UPDATE:
Here is my Apple LLVM 6.0 - Language-c++ settings:
Regular iOS project with that c++11 code compiles without errors.

you need to explicitly add libc++ as a linked library under general tab.

I don't know how far it will work fine in your scenario. I got similar kind of error when I tried to compile and build so. I will share what I did :
1.Goto your project Build Settings.
2.Click Build Settings.
3.Search for Apple LLVM 6.0 - Language-c++ .
4.set c++ standard library as libstdc++ .
Then try compile the project.
This might not the exact solution.
I just shared what worked for me when I am facing the similar kind of errors as yours.
Thank you!

Have you tried setting the C++ Language Dialect to C++11? It's in the same place as the C++ standard library setting:
Go to Build Settings
Select your Target, and click Build Settings.
Search for Apple LLVM 6.0 - Language-C++
Set C++ Language Dialect to C++11.
You might also have to set the C++ Standard Library to libc++.

Xcode adds all headers to the "Headers" build phase by default. So, I solved my issue by removing all unnecessary C++ headers from the build phase.

Related

Could not build module Foundation

I am using a sub-project which has a C++ library that it uses and this project has a SDK that I am trying to use.
I have several projects that I am trying to build, each of which use this SDK. I have some targets that compile fine but then I have some that tell me Could not build module: Foundation.
As I said this happens in some but not all of my targets, I was able to get some to work by clearing the linker flags but this does not fix it on all targets. So it seems weird to me that some targets work fine while others do not.
I have tried:
Removing linker flags
Reinstalling Xcode
Messing with header search paths
Any suggestions? I've been stuck on this for a while.
As don't have more information in question here.
Try making
Allow Non-modular Includes in Framework Modules
to Yes in your Build Settings.

Prevent Xcode 6.3 from linking default libraries and headers when using project templates

I'm building a project in Xcode 6.3. I based it on a command line tool project template. Is there a possibility to exclude the automatically added libraries of such paths and origins like for example curses.h?
Here the path:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/curses.h
Where can I change the default settings of inclusion/exclusion of the default libraries loaded in the target of my project?
Thank you for any hints, since it is awfully hard to find something about it on the web.
It turns out that you can easily disable all the additional modules in Xcode's Build Settings:
Build Settings > Apple LLVM 6.1 - Language - Modules > Enable Modules (C and Objective-C)
and set it to No.
(a broader answer was posted by Thomas Dickey here: How to disable "curses.h" header (a part of "stdio.h in Xcode 6.3 OSX Yosemite) to avoid conflicting function declarations)

Check for framework's existence at compile time?

I'm working on an open-source project that can optionally use a closed-source framework. If the closed-source framework is included in the project, there will be additional functionality. But if the framework isn't included in the project, the project should still compile properly.
How do I check at compile-time if the framework is included in the project?
Basically, I want to do something like this:
#ifdef _MY_FRAMEWORK_EXISTS
#import <MyFramework/MyFramework.h>
#endif
I've seen older questions from 2 years ago like this one, but no answer has surfaced so I might be missing something new now.
I DON'T want to check at run-time via NSClassFromString(), because this will fail at compile time when I try to import MyFramework and it doesn't exist.
You can check for the presence of a header file using the __has_include language extension.
http://clang.llvm.org/docs/LanguageExtensions.html#include-file-checking-macros
However, that only tells you if the header file is installed. It can't tell you if "Link Binary With Libraries" has linked to its framework.
I recommend reading the Mac Developer Library : Framework Programming Guide (which includes a section on Weak Linking).
What do you mean by "exists" or "included in the project"? Do you mean added to the "Link Binary With Libraries" build phase (as described by Including Frameworks)? All that does is affect the linking, not the compilation, build phase. To see this, build. Then, search for -framework in the build log of Xcode's Log Navigator.
So, yes, if you want to affect the compilation of the code you provided, you could manually define the macro _MY_FRAMEWORK_EXISTS.
I don't really understand what you are trying to do. Can you explain what you want at a higher level? Perhaps, there's a better way to go about it.
"Minimal overhead" is nice, but too much magic might be confusing. For example, Xcode's magic hides what really happens when including a framework.
I also recommend checking out how the Facebook SDK for iOS works for high & low-level ideas. It might do the kinds of things you want to do.

zxing in xcode 4.5 and ios 6

As many of you noticed; zxing does not work in latest xcode (4.5/ios 6)
Here is use case:
checkout latest version from trunk (as some fixes were already added)
create single view application in xcode 4.5 with ios 6.0
use README to add dependencies, paths etc (just follow step by step)
add zxingcontroller call to class (renamed to mm)
Compilation fails both for simulator and device
It shows 31 error like this one:
Undefined symbols for architecture i386:
"std::string::c_str() const", referenced from
all 31 errors are similar, difference is in symbols name
May be somebody knows how to solve it with this use case?
p.s. if you have app from previous Xcode, it works. Problem is only if you create new app in Xcode 4.5
The issue you have encountered seems to be C++ standard library related.
Actually, whenever you see linker failures in relationship with standard library objects (e.g. std::string), you should check the project settings on all linked libraries and the app-project itself. They usually need to match!
The original ScanTest (which builds ZXingWidget as a subproject) uses the following settings and those need to match your App build-settings if you use the library as is.
For making sure, I created a brand-new project using Xcode 4.5. That project uses ZXingWidget as a prebuilt library but not as a subproject - I dont like subprojects for stuff that is not my own - though this specialty wont influence the results.
The important setting is C++ Standard Library - make sure that is set towards Compiler Default
Little clarification
Actually, you do not need to use C++ Standard Library, you may as well use LLVM C++ standard library with C++11 support. But you will have to use that exact same library in all projects, sub-projects and libraries that link with your project. So if you insist on using the more recent version of that library (C++11 support), then you will have to build the ZXing library with those settings as well.
Last but not least, make sure your Architectures and Valid Architecture settings are matching over all projects and sub projects (fixing the common armv7s linker issue).
First, make sure your Architectures setting is set towards armv7 armv7s within all projects. Then also edit the project settings of all projects towards Valid Architecture armv7s armv7.
You might also want to switch the "Other Warning Flag" -Werror off. Seems to be necessary in Xcode versions > 4.5 (LLVM compiler > 4.1).
It works for me, have you enabled -lstdc++ in your list of Other Linker Flags in the Build Settings tab of the project target? It sounds like it is not recognizing the c++ symbols needed for zXing to build. If this is the case, the above advice should help.

Framework import issue in xcode

Here the problem: For a project at work we need to include an extern API: mobileAppTrackeriOS from HasOffers.
It gives us a framework to include in our projet and instruction to enter in our code.
So I copy the framework in the project directory and drag it into xcode to include it.
But when i want to use it with:
#import <framework/mainheader.h>
The build give me an error :
Lexical or Processor issue 'MobileAppTrackeriOS_arc/MobileAppTracker.h' file not found
I check the framework search path in my target build setting, my main directory where is the framework is here.
I test with "" instead of <> same issue...
i cleaned and rebuilt, try to include directly the header... many ridiculous things... no changes.
So what I forget?
I'm on Xcode 4.5 and develop for iOS 6.0.
A question, can you see if the framework is in Build Phases -> Link binary with Libraries?
If answer is not, you must add in this section.

Resources