How to mixed C + +

Source: Internet
Author: User

1. How to mixed C + +

Create a project with XCODE4, if the header of any file AAA.h joins

#include <string>

using namespace Std;

Compile run, you will find that the compilation does not pass, the prompt is:

' String ' File not found

The reason is that the file suffix should be changed from. m to. MM, so that it supports C + + mixed, all file suffixes that refer to C + + mixed AAA.h must be changed to. mm, otherwise it will still compile. Therefore, in order to insure, I generally will be so the file suffix all changed to. mm.

2. Selection of C + + standard library

If you chose 4.3 in deployment Target in summary instead of the default of Xcode, you might encounter another error when mixing C + +:

Clang:error:invalid deployment target for-stdlib=libc++ (requires IOS 5.0 or later)

Clang failed with exit code 1

The reason is that the C + + standard library in XCode's Build setting is selected by default

The libc++ (LLVM C + + standard library with C++11 support) option, which supports the latest new special of C++11,

But it only supports ios5 above, so if you want to use this option, there are two options:

The 1th option is to change deployment target to more than 5.0, generally not, because we generally want to support the lower the better, as far as possible to support the lower version of the iOS device.

The 2nd option is to change the C + + standard library option to libstdc++ (the GNU C + + standard library), which supports a minimum of 4.3.

How to mixed C + +

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.