I am getting a build failure on link after adding a new .h and .m file dataparsing and i don’t quite understand why. I’m newer to objective-c though. if i remove the include ( then i have to remove the reference to the object from the file that needs dataparsing class) then it wont fail. just removing the object wont cut it and it still fails when i try to include the files. in the error section under linking it says one duplicate symbol for architecture i386
dataparsing.h is:
//
// dataParsing.h
// TelnetToICC
//
// Created by **** on 10/8/12.
//
//
#import <UIKit/UIKit.h>
@interface dataParsing : UIView
{
}
- (void)getData:NSString:id;
-(void) parseLine:id;
-(void) parseDatagram:id;
-(void) reset;
@end
char icc_data[10000];
int data_top=-1;
the idea is just to write some simple functions for processing strings so i am not trying to do anything real special here but i’m newer to objective-c. The include for dataparsing in ViewController.m is:
#import "dataParsing.h"
#import "ViewController.h"
#import <CoreFoundation/CFSocket.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
@implementation ViewController
It seems like i got something going on twice for the linker but my experiments havent found it. I noticed both my .h files have
#import <UIKit/UIKit.h>
but i remove one and it doesn’t work.
Mike
The duplicate symbol is
_data_top. And I’m guessing also_icc_data. The problem is that you are declaring a global variable in the dataparsing.h file. So for every file that includes this .h file, a new global variable with the same name is created resulting in the duplicate symbol linker error.What you need to do is change the lines:
to:
Then in the dataparser.m file you do:
The extern in the .h file lets the compiler and linker know that there will be one copy of the variable defined somewhere. The lines in the .m file are that one definition.