Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7010357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:58:50+00:00 2026-05-27T21:58:50+00:00

I have a class structure Class A { Object of classB Object of classC

  • 0

I have a class structure

Class A
{
   Object of classB
   Object of classC
}

Now for this purpose I have files A.h/A.m B.h/B.m , C.h/C.m
Now I have a separate file G.h which has a number of global variables which are used by all the class A,B,C
Now I have imported B.h , C.h , G.h inside A.h . I also have separately imported the file G.h inside B.h and C.h

Now when build the project , I receive a link error for duplicate symbol on the global varibles (which is probably due to multiple inclusion of the file G.h) .

How can I solve this ??? The following is my code structure

//A.h

#import "B.h"
#import "C.h"
#import "G.h"

@interface A : NSObject {
  B *b;
  C *c;
}
//B.h
#import "G.h"

//C.h

#import "G.h"

//G.h
A *a=nil;
@interface G : NSObject { //whole class is empty}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:58:51+00:00Added an answer on May 27, 2026 at 9:58 pm

    You should declare your globals in G.h but define them in G.m, so that they’re only linked once in the target. So if, for example, you have a string constant that’s globally defined, you would do:

    G.h

    extern NSString const *appName;
    

    G.m

    NSString const *appName = @"My Great App";
    

    In your pasted code, it’s the A instance that’s being duplicated. It’s imported into each other translation unit, but with the same name every time which means that the compiled objects can’t be linked. Assuming you want a shared A instance called a, you’d do:

    G.h

    @class A;
    extern A *a;
    

    G.m

    #import "A.h"
    #import "G.h"
    
    A *a = nil;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a business object project, which contains composite structure: public class Tree {
I have this class in my parser.py file class HostInfo(object): def __init__(self, host_id): self.osclass
I have a object structure like this: public class Entity { IList<Relationship> Relationships{get;set;} }
Ok, so I have a class for a Advanced Data Structure (in this case
I have a class structure in PHP which I am using to allow for
I have a class structure like abstract class Animal { public Animal(){ //init stuff..
I have the following class structure FlowerDAO with the fields (mapped using Hibernate): id
I have the following class structure: class Organization { string Name; List<User> users; List<Organization>
I have the following class structure public class Outer{ private Mapper a; .... private
Let's say I have the following class structure: class Car; class FooCar : public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.