Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C with some C++ code won't compile

I have an Objective C project with some C++ code, and sure enough the C++ code won't compile

I understand that the compiler makes assumptions about which language to compile, but I have seen this app running before so I am curious how to make my Xcode 4 run compile this project

ie. This function declaration produces an error as the compiler does not recognize the c++ std:: syntax

 std::string string_with_formatting(const unsigned int value)
 {

How do I get around this? What #include or #import should I have

like image 513
CQM Avatar asked Aug 14 '11 04:08

CQM


People also ask

Does Objective-C compile to C?

Compiling Objective-C into C doesn't make sense, because then it would need to parse the C code and compile it. Objective-C compiles into machine code. Remember that the language (Objective-C, C, C++) only defines the rules to correctly write code.

Can I compile Objective-C in Windows?

The best platform for developing Objective‑C is Mac OS. But Objective‑C programs can also be compiled and run on Windows or Linux by using GNUstep and an Objective‑C compiler.

What compiler does Objective-C use?

These days, Xcode ships with clang as the compiler. Wherever we write compiler, you can read it as clang. clang is the tool that takes Objective-C code, analyzes it, and transforms it into a more low-level representation that resembles assembly code: LLVM Intermediate Representation.

Why is Objective-C slow?

Objective-C is slightly slower than straight C function calls because of the lookups involved in its dynamic nature.


1 Answers

Objective-C++ is a superset of C++. You can use C++ in Objective-C++ sources.

  1. Make sure the file has .mm extension, otherwise it will be treated as Obj-C, not Obj-C++
  2. #include <string>
like image 125
hamstergene Avatar answered Sep 21 '22 18:09

hamstergene