Duplicate Interface Definition When Implementing FBConnect - iphone

I am trying to add FBConnect to my application which includes the SBJson framework. However, when I try to compile the project I get these two errors:
Duplicate interface definition for class 'SBJsonWriter'
Duplicate interface definition for class 'SBJsonParser'
What can I do to fix this error? Thanks for any help.

Delete
#import FacebookSDK/FacebookSDK.h
In your project
I start using FacebookSDK, but then I was disappointed with it's current state and tried to use the old "FBConnect", that's how I have got the error

There are two possibilities:
you have two interfaces with the same name. Use Xcode's find in project menu option to find instances of SBJsonWriter. Then rename one of the interfaces
somehow you have managed to import the .h file twice. Check to make sure you always use #import and not #include.
A bit more info on #import/#include:
include blindly includes the file at the location of the #include statement. This means that if you #include a file twice in your .m you will get two copies of the file. Almost all traditional C #include files have something like the following bracketing all the content:
// some_file.h
#if !defined SOME_FILE_H
#define SOME_FILE_H
// entire content of #include file
#endif
he above is sometimes referrwed to as an include guard macro.
In Objective-C, if you #import a file, a check is performed by the compiler to make sure it has not already been imported. Consequently the guards are usually omitted. So if you #include a file that was supposed to be #imported, neither check will be done and you will sometimes get duplicate definitions.

Related

OpenCV project on iPhone - opencv.hpp building issue

I've cloned https://github.com/niw/iphone_opencv_test and tried to replace
#import <opencv2/imgproc/imgproc_c.h>
#import <opencv2/objdetect/objdetect.hpp>
with
#import <opencv2/opencv.hpp>
in OpenCVTestViewController.m file. But XCode threw following error:
iphone_opencv_test/opencv_device/include/opencv2/opencv.hpp:55:10: fatal error: 'opencv2/calib3d/calib3d.hpp' file not found [2]
#include "opencv2/calib3d/calib3d.hpp"
So, I've tried to remove the line #include "opencv2/calib3d/calib3d.hpp" from the opencv.hpp file. The error below was thrown:
iphone_opencv_test/opencv_device/include/opencv2/ml/ml.hpp:2075:10: fatal error: 'map' file not found [2]
#include <map>
I've also tried to change .m to .mm, but it seemed futile. Where I'm wrong?
There's a conflict between OpenCV's MAX/MIN macros and Cocoa's MAX/MIN. It leads to strange errors like this one at compile time. To bypass this problem, you can either:
1. add at the top of the pre-defined header file
2. totally decouple opencv and obj-c code, so that no .m/.mm file includes . This can be done for example by using boost GIL in-between, or using custom vanilla C++ classes to pass image data from Cocoa frameworks to opencv C++ image processing classes.

How to use Grand Central Dispatch in iOS in a .c file

I have some C code in an iOS project that I would like to optimize using GCD. Currently I can only get my code to compile if change my C file to an Objective-C file and import the Foundation framework. What do I have to include in my C file to get access to GCD?
I've tried:
#include <dispatch/dispatch.h>
but that doesn't seem to work it always complains about code blocks having the ^ character
You'll need to tell the compiler to enable Blocks with the -fblocks flag. You'll also need to use a compiler that understands blocks (Clang, for one).
You might need to;
#include <Block.h>
But it's not something I've done myself so could be wrong here.

Need clarification on what's going on when linking libraries in iOS

This is probably a totally noob question but I have missing links in my mind when thinking about linking libraries in iOS. I usually just add a new library that's been cross compiled and set the build and linker paths without really know what I'm doing. I'm hoping someone can help me fill in some gaps.
Let's take the OpenCV library for instance. I have this totally working btw because of a really well written tutorial( http://niw.at/articles/2009/03/14/using-opencv-on-iphone/en ), but I'm just wanting to know what is exactly going on.
What I'm thinking is happening is that when I build OpenCV for iOS is that your creating object code that gets placed in the .a files. This object code is just the implementation files( .m ) compiled. One reason you would want to do this is to make it hard to see the source code and so that you don't have to compile that source code every time.
The .h files won't be put in the library ( .a ). You include the .h in your source files and these header files communicate with the object code library ( .a ) in some way.
You also have to include the header files for your library in the Build Path and the Library itself in the Linker Path.
So, is the way I view linking libraries correct? If , not can someone correct me on this ?
Basically, you are correct.
Compiling the source code of a library produces one object file for each of the source files (in more than one, if compiled multiply times against different architectures). Then all the object files are archived (or packaged) into one .a file (or .lib on Windows). The code is not yet linked at this stage.
The .h files provide an interface for the functionality exposed by the library. They contain constants, function prototypes, possibly global declarations (e.g. extern int bad_global;), etc. -- basically, everything that is required to compile the code which is using the library.
.h files do not 'communicate' with object code in any way. They simply provide clues for the compiler. Consider this header file:
// library.h
extern int bad_global;
int public_func(int, const void*);
By including this file in your own code, you're simply telling the compiler to copy and paste these declarations into your source file. You could have written declarations for OpenCV library and not use the headers provided with it. In other words, you're asking the compiler to not issue errors about undefined symbols, saying "I have those symbols elsewhere, ok? Here are their declarations, now leave me alone!".
The header files need to be included in the search path in order for compiler to find them. You could simply include them via the full path, e.g. #include "path/to/file.h", or supply an -I option for your compiler, telling him where to look for additional headers, and use #include <file.h> instead.
When your code is compiled, the declarations in header files serve as an indication that symbols your code is using are defined somewhere. Note the difference between the words declaration and definition. Header files contain only declarations most of the time.
Now, when your code is compiled, it must be linked in order to produce the final executable. This is where the actual object code stored in the library comes into play. The linker will look at each symbol, function call, etc. in your object code and then try to find the corresponding definition for each such symbol. If it doesn't find one in the object code of your program, it will look the standard library and any other library you've provided it with.
Thus, it is important to understand that compilation and linkage are two separate stages. You could write any function prototypes at all and use them in your code, it will compile cleanly. However, when it comes to the linking stage, you have to provide implementation for symbols used in your code, or you won't get your executable.
Hope that makes sense!
The .a is the compiled version of the code.
The header files provided with a library are its public interface. They show what classes, methods, properties are available. They do not "communicate" with the binary code.
The compiler needs the headers to know that a symbol (a method name for example) is defined somewhere else. They are associated with the right "piece of code" in the library binary later during the "link" step.

Typedef for STL Vector does not compile in XCode

I have some code written in C++ which I would like to use in my iPhone app. I added the source files to the XCode project, but I have problem with some parts of the source code, e.g. I have he following code:
#import <vector>
// (...) some other code
typedef std::vector<keypoint> keypointslist;
// (...) rest of the code
In the line with the typedef I'm getting:
Expected '=', ',', ';', 'asm' or 'attribute' before ':' token in
Exactly the same code was compiled with gcc on Linux machine, so I wonder why XCode has problem with it.
Any suggestions?
Are you sure, you told XCode to compile the file as C++ and not as C or Objective-C? Maybe you must use the file extension ".cpp".
It's called #include, not #import:
#include <vector>
+1 with Ludger,
youre adding that to an objective c app, you'll need to add a .cp/.mm/.cpp translation unit to the project to get that to compile - right click on project classes select add class make sure you add one from the cpp section.
If you include C++ code in a ".m" file you must rename the extension to ".mm" or ".M". this applies even if you reference a C++ class from an objective C one, the file must be renamed. Sometimes this renaming has a domino effect and so you end up with a lot of ".mm" files in your project.
Make sure you included <vector> header file before typedef. It looks like the compiler doesn't know std namespace.
You have to rename the ALL files that use the C++ code with .mm extension.
That includes your view controller files that could be importing the C++ class. eg. MyViewController.mm

Cannot find interface declaration for 'UIResponder'

I am running into this issue when trying to compile code for an iPhone app that I inherited from a previous developer. I've poked around on a couple forums and it seems like the culprit may be a circular #import somewhere.
First - Is there any easy way to find if this is the case/find what files the loop is in?
Second - Its definitely possible this isn't the problem. This is the full error (truncated file paths so its easier to view here):
In file included
from [...]/Frameworks/UIKit.framework/Headers/UIView.h:9,
from [...]/Frameworks/UIKit.framework/Headers/UIActivityIndicatorView.h:8,
from [...]/Frameworks/UIKit.framework/Headers/UIKit.h:11,
from /Users/wbs/Documents/EINetIPhone/EINetIPhone_Prefix.pch:13:
[...]/Frameworks/UIKit.framework/Headers/UIResponder.h:15: error: expected ')' before 'UIResponder'
[...]/Frameworks/UIKit.framework/Headers/UIResponder.h:17: error: expected '{' before '-' token
[...]/Frameworks/UIKit.framework/Headers/UIResponder.h:42: warning: '#end' must appear in an #implementation context
[...]/Frameworks/UIKit.framework/Headers/UIResponder.h:51: error: expected ':' before ';' token
[...]/Frameworks/UIKit.framework/Headers/UIResponder.h:58: error: cannot find interface declaration for 'UIResponder'
As you can see, there are other errors alongside this one. These seem to be simple syntax errors, however, they appear in one of Apple's UIKit files (not my own) so I am seriously doubting that Apple's code is truly producing these errors.
I'm stumped as to how to solve this issue. If anyone has any ideas of things I could try or ways/places I could get more info on the problem, I'd really appreciate it. I'm very new to Obj-C and iPhone coding.
Edit:
Just tried Clean All Targets - it actually found an extra warning but still have the same errors as above.
My EINetIPhone_Prefix.pch:
//
// Prefix header for all source files of the 'EINetIPhone' target in the 'EINetIPhone' project
//
#import <Availability.h>
#ifndef __IPHONE_3_0
#warning "This project uses features only available in iPhone SDK 3.0 and later."
#endif
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#endif
Edit #2:
Interestingly, I tried removing the UIKit import from my prefix file and putting it into the specific .m files that need it. I still get the same errors, but now they occur in every file attempting to import UIKit.h. Is it possible that UIKit is messed up?
Perform a “Clean” (under the “Build” menu) and make sure to check “Also Remove Precompiled Headers”.