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

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?

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.
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.

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.

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.

Related

Xcode Project can not find .framework classes to import

I am working on a project, that reads the bank cards. The card reader company provided a .framework SDK but does not provide any technical support.
I search on Google and find out how to add .framework into the project. I followed the following steps.
Drag and drop the framework file into the project folder.
Adding the framework into Build Setting -> Link Binary With Liberaries.
Adding the Framework Search Path into Build Settings.
After cleaning the project and rebuild still the framework classes are unknown to my project.
Do I miss something? or I am going on the wrong way.
My project is on Swift and the framework is on Objective-C.
You need use bridge header and there you need to import your Objective C framework.

Header file not found for embedded framework inside library for React Native app

I'm currently working on a contract job where I've been asked to help integrate a 3rd party SDK with an existing React Native app. The SDK only comes in Android and iOS specific flavors, meaning that it has to be added on the platform-specific side of things (in my case, the iOS side with Xcode).
For the app, the client has created a react native module which gets built into a Library in Xcode, represented by a separate nested Xcode project in Libraries/MyLibrary.xcodeproj from the root of the base Xcode workspace project. This library has several method stubs defined in React Native which will need to be implemented in Swift (and likewise in Android), as this is in these methods that the 3rd party platform-specific SDK is utilized.
The issue I'm having has to do with accessing the 3rd party SDK framework in the library's existing bridging header file. I have followed every tutorial under the sun for how to integrate external frameworks with an existing Xcode project. This includes steps about adding the framework to the project, adding it under the Embedded Binaries and Linked Frameworks and Libraries sections of the project target, adding it under the Build Phases/Link Binary With Libraries section of both the project target and the library target, and adding the framework path under Project Settings/Framework Search Paths. From here, I add the appropriate import statement to my library's Library-Bridging-Header.h file with #import <MyFramework/MyFramework.h> so I can then access the framework in Swift. (This import statement is copied directly from the bridging header file of the sample project included with the SDK, so I know it is correct and should not be given in a different format such as quotes instead of angle brackets).
Regardless of following all of these steps multiple times over and in various combinations, I still get this error at build time: MyFramework/MyFramework.h file not found.
To clarify, MyFramework is just an alias for the actual 3rd party framework I'm attempting to integrate, and MyLibrary is an alias for the existing library with nothing but method stubs given to me by the client to implement in Swift.
Again, I have read every tutorial and forum under the sun, but none seem to address this very specific issue of integrating a 3rd party framework in a xcodeproj Library within the iOS version of a react native app. I would appreciate any new insights or suggestions anyone might have to offer! And please, please don't just post a link to or copy the steps from existing forum posts about a similar-sounding issue, as I've probably already read it 😉. Understand that I think that there is something subtly unique about my specific circumstances which are causing these same steps from the 10+ articles that come up on the first page of Google and StackOverflow NOT to work.
Figured it out! I'll post my solution here in case anybody out there ever runs into the same issue as me.
TLDR - You must add the 3rd party framework in the root of the xcodeproj Library (NOT the top level project) AND ensure that the files were actually copied into that directory, not just referenced from the directory you copied the framework from (be sure to double-check in Finder, since checking the 'Copy if needed' box doesn't always work for some reason). Then, you must add $(PROJECT_DIR) to your xcodeproj Library's Build Settings/Framework Search Paths, and also drag and drop the framework from the root of your xcodeproj Library into the Library's Build Phases/Link Binary With Libraries panel.
I'll address some of the issues with other tutorials/forums that I found, with hopes that it might help someone else that finds themselves as frustrated as I was in this position.
Most only address adding the framework to the base level project, not the obscure case of a project within a project. Therefore, when you start following the steps, it can be confusing to know whether you should be changing the settings of the top-level project or the sub-project. Again, as I discovered, all changes should ONLY be made to the sub-project.
There are a few tutorials that do seem to address this situation regarding a project within a project, but the steps describe adding the framework to the top-level project under Embedded Binaries and Linked Frameworks and Libraries, but I believe the situation described in these tutorials are somehow subtly different than this situation here. Again, only mess with the sub-project.
There's a lot of discussion out there about "umbrella frameworks", but that doesn't really apply to this situation, and again, the terminology similarities can make it seem like it's a similar issue. As I understand it, "umbrella frameworks" are discouraged by Apple, but again, this situation is not the same.
Sorry for the long-winded explanation, but I'm hoping to provide the kind of detail I would have liked to have found when I was searching for solutions for this weirdly obscure problem.
Cheers!

Wrap a C++ library in Swift code, compile as a Cocoa Touch framework

I have a C++ library that is full of warts and weird features, and I want to make it much easier to use (and reuse) in a Swift project. So I intend to wrap this C++ library in some Swift code, then make it available as a Cocoa Touch framework.
I've added both my (fat) .a file and the required .h files to my project, then added the .a to the "Link Binary with Libraries" section of Build Phases, and added the main .h file to the Project section of the Headers build phase. But the build fails with:
Library not found for -lMyLib
I'm obviously missing something here - I'm guessing maybe I need to adjust the Framework Search Path and/or Header Search Path? Or am I missing something more fundamental? My desired end result is a .framework another developer can pull into their Swift project without having to do any other build setting tweaks.
You're probably looking for "Library Search Paths" (LIBRARY_SEARCH_PATHS). You may need to add to "Header Search Paths (HEADER_SEARCH_PATHS) as well, depending on your setup. In this case, you shouldn't have to add anything to the Framework search paths, since you are not dealing with a Framework.
(As an aside, you are likely going to find that you have to wrap your C++ library in Objective-C++ code to expose the functionality to Swift.)

How to add external framework GPUImage framework? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I am developing iPhone application using iOS. I need to add GPUImage framework, i followed this url for adding purpose. http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework
Now i drag and drop GPUImage xcodeproject file in my project. In this project product folder having libGPImage.a file. It showing empty folder, in this file missing. It showing like red color. I am unable to access GPUImage class files. why it is happening.
Thanks,
As others have commented, I have step-by-step instructions for framework installation on the main GitHub page. I'll reproduce those below:
Once you have the latest source code for the framework, it's fairly
straightforward to add it to your application. Start by dragging the
GPUImage.xcodeproj file into your application's Xcode project to embed
the framework in your project. Next, go to your application's target
and add GPUImage as a Target Dependency. Finally, you'll want to drag
the libGPUImage.a library from the GPUImage framework's Products
folder to the Link Binary With Libraries build phase in your
application's target.
GPUImage needs a few other frameworks to be linked into your
application, so you'll need to add the following as linked libraries
in your application target:
CoreMedia
CoreVideo
OpenGLES
AVFoundation
QuartzCore
You'll also need to find the framework headers, so within your
project's build settings set the Header Search Paths to the relative
path from your application to the framework/ subdirectory within the
GPUImage source directory. Make this header search path recursive.
To use the GPUImage classes within your application, simply include
the core framework header using the following:
#import "GPUImage.h"
As a note: if you run into the error "Unknown class GPUImageView in
Interface Builder" or the like when trying to build an interface with
Interface Builder, you may need to add -ObjC to your Other Linker
Flags in your project's build settings.
Also, if you need to deploy this to iOS 4.x, it appears that the
current version of Xcode (4.3) requires that you weak-link the Core
Video framework in your final application or you see crashes with the
message "Symbol not found: _CVOpenGLESTextureCacheCreate" when you
create an archive for upload to the App Store or for ad hoc
distribution. To do this, go to your project's Build Phases tab,
expand the Link Binary With Libraries group, and find
CoreVideo.framework in the list. Change the setting for it in the far
right of the list from Required to Optional.
Additionally, this is an ARC-enabled framework, so if you want to use
this within a manual reference counted application targeting iOS 4.x,
you'll need to add -fobjc-arc to your Other Linker Flags as well.
If you follow the steps in the first paragraph, when you drag the libGPUImage.a library from the Products folder into the Link Binary With Libraries build stage, it will indeed show up as red. The reason for this is that the static library has not been built yet at this stage. Don't worry about that, because if you follow the previous step of adding the project as a dependency of your application the static library will be built before your application is. Everything should work fine from this point on.
These are the installation instructions I've now used on several applications, and they've worked for each one.
Try this
projet Target > summary > framwork > add Others.> than browser to
"BradLarson-GPUImage-6619cd2/framework>GPUImage.xcodeproj" .
Thi url you provided is not working... anyways, did you try to add *.a file into your project by adding it in the build settings of your target?
You need to follow instruction to add Framework in your project, you can check those under "Adding the framework to your iOS project" section in-
https://github.com/BradLarson/GPUImage

Thrift framework for iPhone

I'm currently stuck trying to get my objective c generated files to compile in my iPhone project. Basically it keeps telling me there is no such directory for the following four imports:
Thrift/TProtocol.h
Thrift/TApplicationException.h
Thrift/TProtocolUtil.h
Thrift/TProcessor.h
I'm following all the instructions on the Thrift wiki and have downloaded and compiled the Thrift framework in XCode but there is no information specific to iPhone development. I'm almost certain it's a problem specific to an iPhone project because if I create a new command line project in XCode, I can import those files just fine.
After retaining the services of some kind of sorcerer I have figured out how to get Thrift to work with the iPhone/iPad (or at least get it to compile okay).
First, you want to grab the objective-c files with this command instead of from the wiki:
svn co http://svn.apache.org/repos/asf/incubator/thrift/trunk/lib/cocoa/src/ thrift-cocoa
Then, make a new Xcode project by going to New Project, selecting Framework & Library and Cocoa Framework. Click create and save it somewhere nice. Right click on Targets and select Add -> New Target. Choose Cocoa Touch and then Static Library. Give it a nice name. Go to the target's Build tab in info and change the Base SDK to iPhone Device (I'm using 3.2 but you can use whatever) and change Architectures to either Standard (armv6 armv7) or Optimized (armv7). Under the General tab add the Foundation and Cocoa frameworks.
Drag all of the files and folders you got from the svn repository into the Classes folder in the project. Check the copy items box and check the boxes next to both targets. Remove TSocketServer.h and .m from the Static Library's Copy Headers and Compile Sources folders respectively. You can now build the Static Library (and Framework optionally).
Open the project you want to use Thrift in and go to your target's General tab in info. Add the Static Library you just created to the Linked Libraries list. It should be named libYOUR_TARGET_NAME.a. Under the build tab go to Header Search Paths and add the path to the Thrift project you just created and check the recursive box.
Finally you just need to change the import statements in the Thrift generated code by simply removing the brackets and replacing them with quotes. You can now build you iPhone project again.
Try adding those .h files to your Xcode project.