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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:33:08+00:00 2026-06-17T11:33:08+00:00

The linker reports duplicate symbol on this: #ifndef testttt #define testttt void anything(){ std::cout<<hellooooooo;

  • 0

The linker reports duplicate symbol on this:

#ifndef testttt
#define testttt

void anything(){
    std::cout<<"hellooooooo";
}

#endif

Because it is inside the include guards, I would expect that this function is only defined once. But apparently not.

I know I can put the word static in front of it and then it will work (which I still find ironic, since static is supposed to give it internal linkage, yet the function can be used from multiple cpp files).

So I guess my two-part question is: 1) Why do the include guards not prevent multiple definitions of this function like they do for other header items, and 2) Why does the static word resolve this when static is supposed to prevent names from visibility in other translation units? I add it, and I can actually call this function from anywhere that includes this header file.

  • 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-17T11:33:09+00:00Added an answer on June 17, 2026 at 11:33 am

    “1) Why do the include guards not prevent multiple definitions of this function like they do for other header items”

    Because each translation unit (i.e. .cpp file) is processed separately and goes through the same conditional. Translation units won’t share the preprocessor definitions encountered by other translation units. This means that all the translation units that will process that header will include a definition for that function. Of course, the linker will then complain that the same function has multiple definitions.

    “2) Why does the static word resolve this when static is supposed to prevent names from visibility in other translation units?”

    Because the static keyword makes a private copy of that function for each translation unit.

    If you want that function to be defined in a shared header, however, you should rather mark it as inline, which will solve your problem and will make the preprocessor guards unnecessary.

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

Sidebar

Related Questions

I keep getting linker errors when I try to set this up. I'm using
I'm having annoying linker issues - VS2010 claims it cannot find this file, but
Unlike this question: Linker Error while building application using Boost Asio in Visual Studio
Im getting this linker error that won't let me compile. It only happens on
Google webmaster tools reports Duplicate title tags on pages where I have pagination. A
I have three tables in my Crystal Reports and it looks like this: Property
This Question is regarding crystal reports sub-report grouping I have around 10 sub-reports each
got this situation. Reports habtm users. So Im trying to paginate just the Reports
I have this Access database that we use to run reports. The report is
I am writing a linker for a Google Chrome Extension. In the gwt.xml file,

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.