Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How come Xcode doesn't automatically link with QuartzCore when the project uses it?

I am somewhat curious for iOS apps development with Xcode, even though we specifically state:

#import <QuartzCore/QuartzCore.h>

in our ViewController.h, when the project is linked, the QuartzCore library is not automatically linked. Why is that?

like image 813
nonopolarity Avatar asked Apr 27 '12 00:04

nonopolarity


3 Answers

Because importing a header is in no way connected to linking against a library.

You will need to add QuartzCore Framework to the list libraries that your target links against.

enter image description here

Why does Xcode not do that automatically?

Well, the headers you are importing are actually part of that framework. So Xcode would have to scan through all of its frameworks, check their headers and possibly automatically link the connected libraries. That is certainly doable for OS-related frameworks but close to impossible for custom frameworks as long as Xcode does not know their location. Sometimes, Apps do actually not want to link against a library just because they use e.g. an enum defined in a header.

like image 186
Till Avatar answered Nov 07 '22 22:11

Till


Xcode doesn't automatically add any libraries other than the base 3. It doesn't take much to just link. Perhaps a future version will detect, but for now you have to go to Build Phases and Link them.

like image 36
Mike Z Avatar answered Nov 07 '22 21:11

Mike Z


The point is that Xcode has no way to know that your project should link with Quartz Core Framework.

#import <QuartzCore/QuartzCore.h> is not enough to say that you need Quartz Core Framework. You can write your own library which included a header file named QuartzCore.h and put it under a folder named QuartzCore. If it is in your include files searching path, it is OK to use, unless you also add the official Quartz Core Framework into your project (which leads to conflicts).

There are other examples. When you import a namespace in Visual Studio for a .NET project, it doesn't automatically add any assembly into "Reference" of your project. It's because you can add a third-party assembly as reference which has the same namespace. You also can add a different version of official .NET Framework assembly.

like image 2
Hailei Avatar answered Nov 07 '22 22:11

Hailei