Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone SDK linking errors with static library

I've built my own static library with components to be reused in my project, and recently had the need to update a bunch of classes. Specifically, some methods' signatures were changed due to the fact that some classes changed names.

What happens now is that the library compiles fine on its own, but, when added to an app project, the project fails to link:

Ld build/Sucursales.build/Debug-iphoneos/Sucursales.build/Objects-normal/armv6/Sucursales normal armv6
cd /Users/nameghino/src/Sucursales
setenv IPHONEOS_DEPLOYMENT_TARGET 3.1
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk -L/Users/nameghino/src/Sucursales/build/Debug-iphoneos -L/Users/nameghino/src/Sucursales/../../Library/MyLibraries/MSSharedLibrary-1.0.0 -F/Users/nameghino/src/Sucursales/build/Debug-iphoneos -filelist /Users/nameghino/src/Sucursales/build/Sucursales.build/Debug-iphoneos/Sucursales.build/Objects-normal/armv6/Sucursales.LinkFileList -dead_strip -lxml2 -ObjC -all_load -miphoneos-version-min=3.1 -framework Foundation -framework UIKit -framework CoreGraphics -lsqlite3.0 -framework CoreLocation -framework MapKit -lxml2 /Users/nameghino/src/MSSharedComponents/Frameworks/MSSharedLibrary/build/Debug-iphoneos/libMSSharedLibrary.a -o /Users/nameghino/src/Sucursales/build/Sucursales.build/Debug-iphoneos/Sucursales.build/Objects-normal/armv6/Sucursales

Undefined symbols:
  "_OBJC_CLASS_$_DataCatalogService_GetSingleRow", referenced from:
      objc-class-ref-to-DataCatalogService_GetSingleRow in libMSSharedLibrary.a(MSDataCatalogSpecification.o)
  **"_OBJC_CLASS_$_DataCatalogService_ArrayOfString", referenced from:
      objc-class-ref-to-DataCatalogService_ArrayOfString in libMSSharedLibrary.a(MSDataCatalogSpecification.o)
  "_OBJC_CLASS_$_DataCatalogService_GetSingleRowResponse", referenced from:
      objc-class-ref-to-DataCatalogService_GetSingleRowResponse in libMSSharedLibrary.a(MSSingleRowResultsParser.o)
  "_OBJC_CLASS_$_DataCatalogService_GetMultiRowResponse", referenced from:
      objc-class-ref-to-DataCatalogService_GetMultiRowResponse in libMSSharedLibrary.a(MSMultiRowResultsParser.o)
  "_OBJC_CLASS_$_DataCatalogService_GetMultiRow", referenced from:
      objc-class-ref-to-DataCatalogService_GetMultiRow in libMSSharedLibrary.a(MSDataCatalogSpecification.o)
  "_OBJC_CLASS_$_DataCatalogService_HelloWorldResponse", referenced from:
      objc-class-ref-to-DataCatalogService_HelloWorldResponse in libMSSharedLibrary.a(DataCatalogService.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status**

The curious thing is that after a lot of project cleanups (both in the app and the lib projects), I still get the same issue. Even after starting a new project, the problem is still there.

I've also taken care to restart Xcode between a clean and a build a couple of times, but no good.

Any ideas on where to look?

like image 384
Nico Avatar asked May 28 '10 18:05

Nico


People also ask

What is static library linking?

In computer science, a static library or statically-linked library is a set of routines, external functions and variables which are resolved in a caller at compile-time and copied into a target application by a compiler, linker, or binder, producing an object file and a stand-alone executable.

What happens when you link a static library?

Static Linking and Static Libraries is the result of the linker making copy of all used library functions to the executable file. Static Linking creates larger binary files, and need more space on disk and main memory.

Could not find or use auto linked library Swiftwebkit Lottie?

Just open your project/ios with xcode, then add a new swift file and that's it!! your problem is solved.

What is static and dynamic library iOS?

statically linked modules are fastest to load (loading non-system dynamic frameworks is pretty expensive while system frameworks are optimized). When using static linking, all the symbols are within the same module, so the app start is fast. dynamically linked modules are slower to load, especially on iOS.


2 Answers

Have you added the library as a dependency to the project? See Xcode 3.1.1 and static libraries

If you drill down into your target, does the library name appear in the "Link binary with libraries" group?

Look at the log for the compiler/linker output. Find the call to the linker. Does your library appear on the list of static libraries to link in?

like image 79
Shaggy Frog Avatar answered Sep 27 '22 21:09

Shaggy Frog


Yes I solved this error .. a Big Thanks to @Shaggy Frog

Error

I was using some YouTube classes and its giving me below error

enter image description here

Solution

We need to add the Lib Classes to "Compiler Sources" in "Build Phases" option.

  1. Go to Project's Build Phases and click on Compiler Sources option (see below screen). enter image description here

  2. Then Add the classes here

now make Project Clean and Go for Build.

Hope it helps :)

like image 32
swiftBoy Avatar answered Sep 27 '22 21:09

swiftBoy