0

I was asked this about a month back. It is not exactly my line of work, yet I'm curious. They basically had some music libraries in C and wanted to make them available for ios code.

If I have some .c or .cpp files. How can I use them in an ios project. Again this can be confusing as I'm not giving you any context. But any useful links or help is appreciated.

CalZone
  • 1,701
  • 1
  • 17
  • 29

2 Answers2

3

Just add them to the project, you don't have to do anything special. XCode (and clang) will know what language they are from the extension and compile them appropriately.

You might need to tell xcode to link to libstdc++, but that would be it.

Kevin
  • 53,822
  • 15
  • 101
  • 132
  • No need to change `.cpp` to `.mm` anymore? – Mike D Feb 27 '13 at 19:59
  • @MikeD nope, xcode handles cpp just fine (and even has a template for it). Though if you want to use aspects of both, you need to name it .mm. – Kevin Feb 27 '13 at 20:02
  • So, only if there is a reference to a foundation object requires the `.mm` extension. – Mike D Feb 27 '13 at 20:03
  • 1
    Technically, a reference to any objective c object, which I believe doesn't necessarily need to be foundation. – Kevin Feb 27 '13 at 20:06
2

iOS is based on Objective-C which is a superset of C. For all intents and purposes, things should "just work" when compiling C under objective-C. All your structs, function pointers, and everything else you learned in C are still valid and should compile under objective-C.

In-fact, some of the iOS framework pieces (CF, etc) are written in C.

Is objective C 2.0 a proper superset of C?

C++, however, is a different matter :)

Community
  • 1
  • 1
Forhad Ahmed
  • 1,761
  • 13
  • 18