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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:52:21+00:00 2026-05-20T10:52:21+00:00

Unfortunately I cannot post all of the source code here. I can describe the

  • 0

Unfortunately I cannot post all of the source code here. I can describe the structure though. All header files have #ifndef/#define/#endif guards. The structure is as follows:

  • node.h – included by tree.h
  • tree.h – included by tree.cpp and main.cpp
  • tree.cpp
  • main.cpp

In node.h in the global namespace, I declare the following free standing function:

bool char_sort_func(Path first, Path second)
{
  return (first->label() < second->label()); 
}

(Note: as shown bellow, a Path is just a shared_ptr) When I try to build, I get a multiple definition error saying that the function is present in both tree.o and main.o:

> make
g++ -c -g -Wall main.cpp -I /usr/include
g++ -c -g -Wall tree.cpp  -I /usr/include
g++ -Wall -o tool tree.o main.o -L /usr/lib -l boost_program_options
main.o: In function `char_sort_func(boost::shared_ptr<Edge>, boost::shared_ptr<Edge>)':
node.h:70: multiple definition of `char_sort_func(boost::shared_ptr<Edge>, boost::shared_ptr<Edge>)'
tree.o:node.h:70: first defined here
collect2: ld returned 1 exit status
make: *** [all] Error 1

I tried searching all of the source files to see if that was true, however, I don’t see it in any wrong places:

> grep char_sort_func *
Binary file main.o matches   
node.h:bool char_sort_func(Path first, Path second) 
node.h:    std::sort(edges_.begin(), edges_.end(), char_sort_func);
Binary file trie.o matches

Sure enough though, it is in the binary files. How can I restructure my code to prevent this linking issue?

  • 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-20T10:52:21+00:00Added an answer on May 20, 2026 at 10:52 am

    This will happen if you declare normal functions in a .h file, because they will be generated in every file that #includes it. Perhaps you meant to declare it inline or static?

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

Sidebar

Related Questions

I'm trying to do something similar I was asking for here and unfortunately I
I have a little issue as my preg_match_all is not running properly. what I
I have an MS Access database (.mdb) with a front end of reports built
So the gist is that I need to post XML data query to a
I searched SO and google and saw only problems while doing this, unfortunately for
I am trying to create a preference pane which will reside within system preferences.
I'm trying to read some JSON data from the Tumblr API. I'm using the
I am hosting a WCF service using HTTPS, and I am running into a
I am posting a form with the following: if ( flag ) { jQuery.ajax({
My problem is that I'm using the CKEditor 3.4 plugin for jQuery, and it's

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.