2

I am building a static library for an iOS 7 software which uses both C++ and Objective-C++ code.

Trying to put in Objective-C++ (.mm) in the same library as the C++ gives me the following errors in link time:

Undefined symbols for architecture i386:
  "_OBJC_CLASS_$_XYZ", referenced from:
      objc-class-ref in ViewController.o
  "_OBJC_CLASS_$_Thisissomefunc", referenced from:
      objc-class-ref in ViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Is this even possible or should I separate the obj-c++ from the c++ and use two static libraries?

Thanks

shul
  • 221
  • 3
  • 10
  • 1
    Yes, it's possible. So is class `XYZ` and `Thisissomefunc` part of the static library? – trojanfoe Nov 24 '13 at 09:57
  • Yes, it seems like it is possible, my problem was probably that I dragged the files from another project into this static library internal project and the file list to compile did not update. I am using xCode 5.0.2 – shul Nov 24 '13 at 10:38
  • So you need to look at what files and symbols are within the static library. Do that from the command line using `ar t /path/to/lib.a` and `nm /path/to/lib.a`. – trojanfoe Nov 24 '13 at 10:41
  • I swear I've run across this several times before. I will update with an answer if I can reproduce it. I believe all I had to do was change some build settings... – MechEthan Jan 03 '14 at 18:51
  • Thanks. I think the thing that eventually helped was to make sure both libraries and binary are all compiled with exactly the same flags.. – shul Jan 08 '14 at 12:45
  • Also you will most likely need to change the extension of the files used to indicate that they contain both XCode and standard C++. With the right extension the compiler knows how to handle mixed source files. For Objective C & C++ the extension should be ".mm" – Dan Feb 21 '14 at 04:43
  • That is correct. without using .mm objective c++ will not take effect. – shul Feb 23 '14 at 12:34
  • possible duplicate of [Can I use C++11 with Xcode?](http://stackoverflow.com/questions/4574246/can-i-use-c11-with-xcode) – slf May 01 '15 at 14:08

0 Answers0