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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:03:59+00:00 2026-05-30T00:03:59+00:00

I have rand.cpp and rand.hpp file and have rand_unif() function. I have included rand.hpp

  • 0

I have rand.cpp and rand.hpp file and have rand_unif() function.
I have included rand.hpp file in sim_engine.hpp file.

In main.cpp file, I have included sim_engine.hpp file.
If I run makefile then I got this error

ld: duplicate symbol rand_unif()    in sim_engine.o and main.o for architecture x86_64
collect2: ld returned 1 exit status

sim_engine.hpp is the only place where includes rand.hpp.
main.cpp does not include rand.hpp but sim_engine.hpp.

I don’t understand why I am getting the duplicate symbol error.

#mod_simu.make project makefile

mod_simu : main.o rand.o graph.o street.o isection.o vehicle.o event.o FEL.o sim_engine.o clock.o
    g++ -o mod_simu main.o rand.o graph.o street.o isection.o vehicle.o event.o FEL.o sim_engine.o clock.o

main.o : main.cpp   
    g++ -c main.cpp

rand.o : rand.cpp
    g++ -c rand.cpp

graph.o : graph.cpp graph.hpp street.hpp isection.hpp
    g++ -c graph.cpp

street.o : street.cpp street.hpp
    g++ -c street.cpp

isection.o : isection.cpp isection.hpp street.hpp
    g++ -c isection.cpp

vehicle.o : vehicle.cpp vehicle.hpp
    g++ -c vehicle.cpp

event.o : event.cpp event.hpp
    g++ -c event.cpp

FEL.o : FEL.cpp FEL.hpp
    g++ -c FEL.cpp

sim_engine.o : sim_engine.cpp sim_engine.hpp
    g++ -c sim_engine.cpp

clock.o : clock.cpp clock.hpp
    g++ -c clock.cpp
clean:
    rm *.o mod_simu

#end

This is the makefile I have.

  • 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-30T00:04:01+00:00Added an answer on May 30, 2026 at 12:04 am

    You have evidently defined rand_unif multiple times in your program. You probably only define it once in textual code, but through header inclusion, that code gets compiled into multiple .o files.

    You probably defined rand_unif in rand.hpp. That header gets included is included by sim_engine.hpp, so any .cpp file that includes sim_engine.hpp will automatically get a copy of rand_unif. Apparently, both main.cpp and sim_engine.cpp include sim_engine.hpp, so both those .o files get a copy of the function. C++ forbids having multiple definitions of the same function, but it does not require enforcement of that requirement. (It’s called the one-definition rule.) The linker has caught you.

    There are two typical solutions to the problem:

    • Move the definition of the function into a .cpp file; rand.cpp seems like a good candidate. Make sure that rand.hpp contains only a declaration, not a definition.

    • Change the definition in the header file to be inline. C++ makes an exception to the one-definition rule for inline functions. Add inline before the declaration in rand.hpp.

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

Sidebar

Related Questions

I have some 2D points on my image/figure. I use this function im_data= rand(100,2);
I think I have a problem with my makefile. I'm writing this program: Q2.cpp
This is what I have so far: myArray.map!{ rand(max) } Obviously, however, sometimes the
I have this code: Random r = new Random(); while (mStack[step].hasNext()) { int rand
I have created a captcha which looks like this: <img src=/cgi-bin/rand.pl /> The problem
i have this matrix experiment=2*rand(npoints,3)-1 . I want to plot in in 3D,so i
So far I have: $qb1 = $this->getEntityManager()->createQueryBuilder(); $qb1->select('s') ->from('\My\Entity\Song', 's') ->where('s.id <> ?1') ->orderBy('RAND()',
I have some points like this: matrix = rand(6, 4) 0.8147 0.2785 0.9572 0.7922
I have this query: UPDATE people SET column1 = ( SELECT if(r.rand BETWEEN 103
I have an excel sheet, where cells A1-C20= =INT(RAND()*10) . This is my data

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.