Duplicate symbol - iphone

I recently added some openfeint code to my classes and changed them to .mm
All of a sudden I get errors that duplicate symbols are found in the object files when building.
ld: duplicate symbol _audioPlayer in blah blah /Objects-normal/i386/Stage2.o and /Users/blah blah .build/Debug-iphonesimulator/blah.build/Objects-normal/i386/Stage1.o
Why is it suddenly causing this error? What exactly is the error?
I have variables with the same name in different classes, it should be a problem?
Thanks

You're probably declaring two variables with the same name in global scope (not inside interfaces), and the linker is complaining about that.

This error can also occur if you import a .m file instead of .h.
#import "SomeClass.m"

The short answer is that you can suppress this error with a command line argument to gcc:
-Wl,--allow-multiple-definition

If you implement your method like below in .mm file, duplicate symbol errorwill occur.
#import <Foundation/Foundation.h>
class CppTestOne
{
public:
void Test();
// {
// NSLog(#"Hello C Plus Plus");
// }
};
void CppTestOne::Test()
{
NSLog(#"Hello C Plus Plus");
}
then you can implement your method by
#import <Foundation/Foundation.h>
class CppTestOne
{
public:
void Test()
{
NSLog(#"Hello C Plus Plus");
}
};
//void CppTestOne::Test()
//{
// NSLog(#"Hello C Plus Plus");
//}
more details for this error not clear

Related

Import less files within the scope of a mixin

Im researching for this a while now, but i cant figure it out.
#theme: 'example';
// works
#import (reference) "../themes/#{theme}";
.import(#theme) {
// doesn't work
#import (reference) "../themes/#{theme}";
}
i guess the mixins get called at the "end" of the compiling process, so it cant import there because it needs the variables earlier.
is there some known hidden secret workaround for this?
this code
.import(#theme) {
// doesn't work
#import (reference) "../themes/#{theme}";
}
.import(hello);
failed because of
SyntaxError: variable #theme is undefined in less/capsule.less on line 33,

Calling C function in Objective-C block (Linker error)

I have created C function:
header
//FileSystem.h file
#import <Foundation/Foundation.h>
BOOL AddSkipBackupAttributeToItemAtURL(NSURL *url);
implementation
//FileSystem.mm
#import "FileSystem.h"
#import <sys/xattr.h>
#import <Support/Support.h>
static const char* attrName = "com.apple.MobileBackup";
BOOL AddSkipBackupAttributeToItemAtURL(NSURL *url) {
BOOL operationResult = NO;
// some implementation
return operationResult;
}
When i'm calling AddSkipBackupAttributeToItemAtURL from another parts of application everything is OK, except one place where i'm calling function from the block.
__block UpdateFileAsyncOperation* selfOperation = self;
_contentDownloader.completionBlock = ^(NSData* data) {
[data saveForcedToPath:selfOperation.filePath];
NSURL* fileUrlWithScheme = [NSURL fileURLWithPath:selfOperation.filePath];
AddSkipBackupAttributeToItemAtURL(fileUrlWithScheme);
[runLoop removePort:port forMode:NSDefaultRunLoopMode];
[selfOperation completeOperation];
};
In that place ,while linking in progress, there is error:
Undefined symbols for architecture i386:
"AddSkipBackupAttributeToItemAtURL", referenced from:
__36-[UpdateFileAsyncOperation start]_block_invoke in UpdateFileAsyncOperation.o ld: symbol(s) not found for architecture
i386 clang: error: linker command failed with exit code 1 (use -v to
see invocation)
I don't understand why it happens, how it depends on block? and how can I fix that?
Thanks!
Update: it is not dependent on block, i have moved calling of function to another place of class: the error still there. I'm trying to find why
I have solved the problem.
It not dependent on block. It dependent on file extensions.
The problem file was with ".m" extension, other files was with ".mm" extension.
So I have putted next macro in FileSystem.h file
#ifdef __cplusplus
extern "C" {
#endif
BOOL AddSkipBackupAttributeToItemAtURL(NSURL *url);
#ifdef __cplusplus
}
#endif

Duplicate symbol _calculate_string error message iPhone

This is the error code i get when i attempt to build for testing, how do i find the cause for this error. I had duplicted 2 files in xcode and made subtle changes to copy in order to make a second screen.
ld: duplicate symbol _calculate_string in /Users/Lucky3kj/Library/Developer/Xcode /DerivedData/MiniCalculator-ebxkovztnlrphaahncircdyuwjgc/Build/Intermediates/MiniCalculator.build/Debug-iphoneos/PipeFitter.build/Objects-normal/armv7/RollingOffsetLeftViewController.o and /Users/Lucky3kj/Library/Developer/Xcode/DerivedData/MiniCalculator-ebxkovztnlrphaahncircdyuwjgc/Build/Intermediates/MiniCalculator.build/Debug-iphoneos/PipeFitter.build/Objects-normal/armv7/RollingOffsetAnyAngleViewController.o for architecture armv7
Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/clang failed with exit code 1
Basically, this is an error that stems from C.
If, in one .c file I have the following:
void myFunction(int myArg)
{
printf("%i", myArg);
}
And in another file I have this function:
void myFunction(int myArg)
{
printf("MyArg is: %i", myArg);
}
When the compiler links your project, and you call
myFunction(10);
The compiler does not know which version of your method to call, so the solution is one of the following:
1) Define the method once, and include only the prototype of the function. Example:
// instead of implementing myFunction here, we do this:
void myFunction(int myArg);
// and implement myFunction in another file.
-(void) viewDidLoad {
myFunction(10);
}
2) Define the method twice, but add the static qualifier to it, which tells the linker that this is the only file that can use this function.
// FileOne.c
static void myFunction(int myArg)
{
printf("myArg is: %i", myArg);
}
// FileTwo.c
static void myFunction(int myArg)
{
printf("%i", myArg);
}
Honestly, for simplicity, I would recommend just using the static qualifier, but thats just my preference when It comes to these matters.
This error generally come where you have done a circular reference or making two class files with same name.

Strange LLVM warning: no previous prototype for function for

If I missed the prototype, XCode (LLVM) prompt me for error
no previous prototype for function for exceptionHandler
But why they are needed in my code below?
void exceptionHandler(NSException * exception); // Why this Line is needed?
void exceptionHandler(NSException * exception)
{
// ....
}
#implementation AppDelegate
- (void) applicationDidFinishLaunching:(UIApplication *)application
{
NSSetUncaughtExceptionHandler(&exceptionHandler);
...
From the GCC manual:
-Wmissing-prototypes (C and Objective-C only)
Warn if a global function is defined without a previous prototype declaration. This warning is issued even if the definition itself provides a prototype. The aim is to detect global functions that fail to be declared in header files.
Clang borrowed this option for GCC compatibility, and because it's useful (I would presume this of the Clang devs).
The option exists so you can prevent yourself from making a common mistake which may be easily avoided. It's nice to be explicit about visibility/linkage for clarity/intent's sake.
In short, you've asked the compiler to tell you when an unqualified definition does not match a declaration by enabling this option. You should either qualify that as extern and make it usable to others (e.g. put it in a header), or declare it static. If using C++ inline is also an option.
Of course, implicit visibility is well known, but I typically find the option useful in these scenarios:
1) I made a typo:
// file.h
extern void MONExceptionHandler(NSException * exception);
and
// file.m
void MONExceptionhandler(NSException * exception) {
…
2) I should be explicit about the symbol's visibility:
// file.m
static void MONExceptionHandler(NSException * exception) {
…
3) I forgot to #include the header which declared the function:
// file.h
extern void MONExceptionHandler(NSException * exception);
Warning:
// file.m
void MONExceptionHandler(NSException * exception) {
…
No Warning:
// file.m
#include "file.h"
void MONExceptionHandler(NSException * exception) {
…
So there's the rationale, history, and some examples - again, -Wmissing-prototypes is an option. If you trust yourself to work with it disabled, then do so. My preference is to be explicit, and to let programs detect potential and actual issues so I don't have to do it manually.
If you're declaring a function only for use within this file, prefix the declaration with the static keyword and the warning will go away. As it is, you're declaring a global function; theoretically it could be called from anywhere within your app. But as you've given it no prototype, nobody else could call it.
So the warning, as I understand it, is trying to make you clarify your intentions between static functions and global functions, and discourage you from declaring a global function when you meant to declare only a static one.
I think this is most useful for C++ code. For example I have header
class MyClass {
public:
void hello();
};
and .cpp file
void hello() {
cout << "hello";
}
And you will see the warning because there are no prototype for function void hello(). In case the correct implementation should be
void MyClass::hello() {
cout << "hello";
}
So this warning make sure you are implementing the function that you are aware of (not miss typed a name or different argument format).
That warning is alerting that you can't call your method from another method that is written above. In C, the order of the declaration/implementation minds a lot and gives the difference between something that you can access or you can't.

XCode compilation error for C++ code

I am trying to use my C++ classes for an iPhone app. I got 2 compilation errors in XCode that I do not quite understand. Here is the first one, in this header file myApps.h, I declare a class myApps and a struct PointF:
#pragma once
struct PointF {
float x;
float y;
}; // **compilation error message here :Multiple types in one declaration**
class myClass {
...
}
The second error is in a header file too,
#pragma once
class myClass1;
class myClass2;
class MyClass
{
public:
MyClass(void *view);
~MyClass();
virtual void Draw(myClass1 *c1);
//Error: Candidate is virtual void MyClass::Draw(myClass1 *)
virtual void Move(myClass2 c2[], myClass1 *c1, void *callback);
//Error: Candidate is virtual void MyClass::Move((myClass2, myClass1*, void*)
};
Thanks for your help
Ok, I don't know if this will help you but, from what I see:
myClass should have a semicolon at the end:
class myClass {
...
};
For the Candidate is virtual void MyClass::Draw(myClass1 *) below the last function of your class:
using myClass1::Draw;
using myClass1::Move;
since you probably have a method Draw and Move in myClass1... More on it here. It's hard to figure out exactly since I can't see the stuff in myClass1 and myClass2.
Just check Whether your file extension is .m or .mm for C++ files it must be .mm extension.