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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:04:25+00:00 2026-06-02T13:04:25+00:00

I always get a build error when I try to define a C function

  • 0

I always get a build error when I try to define a C function in the header file just above the interface of the class.

but when I do the same in the implementation file and give a declaration in the header. Things work out.

I wanted to know, why is it so becuase I have defined enums, structs , constant NSStrings in the header-file , so why not C functions ?

  • 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-02T13:04:26+00:00Added an answer on June 2, 2026 at 1:04 pm

    This is to do with the way that the C linker (or link editor) works. When the C compiler comes across a function definition, it prepares the assembler code that implements that function and marks it with a symbol that says to the linker “this is where the function with this name starts”. The symbol is usually named with an underscore followed by the function name, e.g. _printf.

    If you define the function in a header file, then every .c or .m file that imports this header will compile the function, and will cause the compiler to emit the same symbol. The linker expects to only find one instance of each symbol, so this is an error.

    This is unrelated to the existence of #include guards, or to using #import instead of #include. The C compiler works on individual translation units – by which it means individual source files. Preprocessor strategies stop you including the same header file twice into a single source file, but do nothing to coordinate activities across multiple files. That means that it’s valid to include the same headers in different source files: it also means that when you compile different files, they can (legitimately) contain the same symbol.

    It’s the job of the link editor to put these files together, resolving any references to symbols that were unknown at compilation time. If you try to link objects (the name of compiled and assembled translation units) that have the same symbol into the same archive, shared library or executable, then you’ll get the error you’re seeing here.

    Solutions:

    • Don’t define the function in the header, just declare it there and define it in an implementation file; as you’ve already found this works.
    • Define the function in the header, but only include that header in one place in your code. This is often unacceptable for design reasons.
    • Define the function in the header with the modifier inline. Inline functions are just copied by the compiler into the function where they’re called, so a linker symbol is never emitted for them. This has its own trade-offs that you may wish to read more about.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get this running: JAXB interface But I always get the error
I'm trying to get title of simple html document to build sitemap. But always
I always get this error when trying to compile my file with Boost::GIL PNG
I always get java.lang.OutOfMemoryError: Java heap space error when I try to run any
I am trying to run google chroome with webdrive but i always get error
Why do I always get the following error from Postgres? syntax error at or
I tried many things but I always get cannot convert string to membershipuser from
**In any javaProject in eclipse there we always get .classpath file...like <?xml version=1.0 encoding=UTF-8?>
Possible Duplicate: Why do I always get the same sequence of random numbers with
I try to include QuickDialog into one of my projects and just can't get

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.