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 8661823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:35:27+00:00 2026-06-12T16:35:27+00:00

In my Xcode project I made a standalone header file with the following C

  • 0

In my Xcode project I made a standalone header file with the following C utility function:

#ifndef FOO
#define FOO
CGFloat DistanceBetweenTwoPoints(CGPoint p1, CGPoint p2)
{
    CGFloat dx = p2.x - p1.x;
    CGFloat dy = p2.y - p1.y;
    return sqrt(dx*dx + dy*dy);
};
#endif

Even with the preprocessor directives, if I try to import or include that header file in multiple locations, I receive the following error complaining about duplicate symbols:

linker command failed with exit code 1

Is there a different way I can achieve this effect? This question is out of curiosity more than anything else.

Thanks

  • 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-06-12T16:35:29+00:00Added an answer on June 12, 2026 at 4:35 pm

    Put your function body in a .c file and the function declaration (aka prototype) in the .h with those #ifndef, etc. Then use include to import the header file where you need the function.

    Remember to check the target membership of the .c file, otherwise it won’t be compiled.

    For a small function like that you can declare it inline and just use the header file:

    inline CGFloat DistanceBetweenTwoPoints(CGPoint p1, CGPoint p2)
    {
        // code as is
    }
    

    The compiler will replace your function calls with the function code without actually building and linking a new object file. No more duplicated symbols.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made a new Console Application Project in XCode, and in the main.c file,
I have made a ViewController in XCode for an iPhone project I'm working on,
In my Xcode project's plist file, I can see the value for the key
I made a new project in XCode (console application). Then I added a new
I made a xcode project where i did some security stuff and they asked
I've made a new project as a Single View iOS Application in Xcode. I've
In Xcode 4, after completing any of the File|New wizards (e.g. File, Project), is
I have made a Xcode project for a tabbed application that displays images of
I was working on an xcode project called Test, which I then made a
I made some changes in my xcode project, which somehow, causes me to not

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.