2

I try to create Cocoa Touch Static Library and follow these steps.

  1. Create New Project with Cocoa Touch Static Library named it By default i got single class with Demo.h and Demo.m.

2.Create a public function in .h and implement it in .m.

3.Select iOS Device and press cmd + B.

4.Copy Demo.a from products and the .h file drop it in my iOS App where i want to use it.

5.Then Import Demo.h and try to call the function that i wrote.

Issue

When try to Run the project showing this error.

ld: warning: ignoring file /Users/Zenga/Documents/iOS/Static Library/myAppwithLib/Demo.a, file was built for archive which is not the architecture being linked (i386): /Users/Zenga/Documents/iOS/Static Library/myAppwithLib/Demo.a
Undefined symbols for architecture i386:
  "_OBJC_CLASS_$_Demo", 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)

Please help if anyone have any idea about it. As these type of error occur if your class' .m file is not listed under the "Compile Sources" but in this case Libraries and I checked Demo.a is also there.

Buntylm
  • 7,345
  • 1
  • 31
  • 51

3 Answers3

0

You can get this type of error if your class' .m file is not listed under the "Compile Sources" step of the "Build Phases" tab of your target. Insert ViewController.m class in Build Phases manually & then check.

Vishal
  • 8,246
  • 6
  • 37
  • 52
  • Check this link & follow: http://stackoverflow.com/questions/6984368/undefined-symbols-for-architecture-i386-objc-class-skpsmtpmessage-refere... – Vishal Jun 28 '13 at 04:23
  • i checked in `Link Binary with Libraries` My Lib `Demo.a` is already there. – Buntylm Jun 28 '13 at 04:27
  • Check that your all .m classes is present in Compile sources or not under build phases???? – Vishal Jun 28 '13 at 04:29
  • sorry for that but i created `Library` here and it already there then why `.m` ? – Buntylm Jun 28 '13 at 04:33
  • Please first look & follow every solutions from link that i have provided to you.... – Vishal Jun 28 '13 at 04:40
  • ok, when i try to add the `Demo.m` file as `Demo.h` i imported. this file is not there as i copy only the `Demo.a` library file and the header file ? – Buntylm Jun 28 '13 at 04:42
  • no as i learn while creating `Library` i need to copy only the Library and the headers as i did only `Demo.a` and `Demo.h` – Buntylm Jun 28 '13 at 04:52
  • But your demo.m class is also be present in compile sources...check it if it is not present there then add it manually.... – Vishal Jun 28 '13 at 04:55
  • as i learned in case of creating framework we need to share only the `.a` and `.h` files so why i import `.m` as i created `Cocoa Touch Static Library`. – Buntylm Jun 28 '13 at 04:57
  • as you told `check it if it is not present there then add it manually.` so why need to add it as i added `.a` files in Library ? – Buntylm Jun 28 '13 at 05:01
0

Check the following:

Select your project
Select "Build Settings"
Check Architectures: Valid architectures should be "armv6 armv7"
Supported platforms should be "iphonesimulator iphoneos" (maybe iPad, I don't know)
Base SDK – your iOS SDK (I have iOS 5.0).
Make sure the 'Build Active Architecture Only' setting is set to 'NO'.

Updated

When you're building a library you must compile it both for the simulator and the device and then merge the two outputs (.a files) into 1 library and then link it to your iOS project.

lipo -create libHelloWorldCppLibPhone.a libHelloWorldCppLibSimulator.a -output libHelloWorldCppLib.a

and imported the merged result to my iOS project

Manish Agrawal
  • 10,958
  • 6
  • 44
  • 76
0

I had this issue and I solved it with this tutorial

http://www.cnblogs.com/simonshi2012/archive/2013/06/18/3141541.html

It builds the compile script in so you only have to click build still and your library will be compiled with both versions together.

walsh06
  • 97
  • 1
  • 9