Thread: error

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    13

    error

    the instructions for this program is to use newton method to find zeros of a cubic function. cubics.h is given and it includes function prototypes and we have to write four functions on cubics.c. findroot.c has the main function and includes cubics.c and cubics.h. when compiling it, i get the error:



    they say:
    cubics.o (.text+0x68): In function 'cubic': multiple definition of
    'cubic'
    findroot.o(.text+068): first defined here

    and then it does the same for the rest of the four functions in cubics.c,
    but
    at the end it says

    collect2:ld returned 1 exit status

    any ideas on whats wrong?

  2. #2
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    715
    Post code so we can see where multiple definition occur. You must know that in C multiple declaration is allowed but multiple definition isn't

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Sounds like you've got multiple declarations of 'cubic' to me. Perhaps one in 'cubics.c' and another in 'findroot.c', but that's just a wild guess...

    On a related note, if this is true:
    and includes cubics.c and cubics.h.
    Then stop #include-ing 'cubics.c' and try just compiling it and linking it instead.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Jul 2004
    Posts
    13
    well our professor gave us the makefile but i think i have multiple definitions of cubics.c, ill check it out now

  5. #5
    Registered User
    Join Date
    Jul 2004
    Posts
    13
    findroot includes cubics.c and findroot.c, cubics.c inclues cubics.h but cubics.h has the #ifdef

  6. #6
    Registered User
    Join Date
    Jul 2004
    Posts
    13
    sorry, i meant findroot.c includes cubics.h and cubics.c and cubics.c includes cubics.h

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >findroot.c includes cubics.h and cubics.c
    There's your problem. You don't need to include cubics.c here.

  8. #8
    Registered User
    Join Date
    Jul 2004
    Posts
    13
    yea that was it! thanks

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    So kind of like I said in the first reply. No, make that exactly like I said.

    Quzah.
    Hope is the first step on the road to disappointment.

  10. #10
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Quote Originally Posted by quzah
    So kind of like I said in the first reply. No, make that exactly like I said.

    Quzah.
    And twelve hours later, the lightbulb turns on.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM