ANSI C Compilation linking problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ben

    #1

    ANSI C Compilation linking problem

    I get an error when the compilator tries to link the object files of
    my program. I have the files group.h and group.c that use a struct
    define in logic.h and two fonctions define in logic.c.

    The program compile group.o fine, but when trying to link, I get an
    error in group.h saying that a struct that is defined in logic.h
    cannot be found. Include logic.h is explicitly call in group.h because
    it used an instance of that struct. What I dont understand is how,
    when the program compile, it is able to find the reference to the
    struct in logic, but when he tries to link, he does not find it
    anymore.

    If I take all the code from logic.h and logic.c and I copy it in
    group.h and group.c respectively, it links fine.

    I don't know what else to try, any ideas is welcome.

    Benoit Grimard
  • Richard Bos

    #2
    Re: ANSI C Compilation linking problem

    ori_grim@hotmai l.com (Ben) wrote:
    [color=blue]
    > I get an error when the compilator tries to link the object files of
    > my program. I have the files group.h and group.c that use a struct
    > define in logic.h and two fonctions define in logic.c.
    >
    > The program compile group.o fine, but when trying to link, I get an
    > error in group.h saying that a struct that is defined in logic.h
    > cannot be found.[/color]

    This sounds suspicious. By the time you're linking, you shouldn't be
    refering to group.h any more - by then they should all be object files
    created during the compilation stage. What precisely is the error you
    get?

    Richard

    Comment

    • john_bode@my-deja.com

      #3
      Re: ANSI C Compilation linking problem



      Ben wrote:[color=blue]
      > I get an error when the compilator tries to link the object files of
      > my program. I have the files group.h and group.c that use a struct
      > define in logic.h and two fonctions define in logic.c.
      >
      > The program compile group.o fine, but when trying to link, I get an
      > error in group.h saying that a struct that is defined in logic.h
      > cannot be found. Include logic.h is explicitly call in group.h because
      > it used an instance of that struct. What I dont understand is how,
      > when the program compile, it is able to find the reference to the
      > struct in logic, but when he tries to link, he does not find it
      > anymore.
      >
      > If I take all the code from logic.h and logic.c and I copy it in
      > group.h and group.c respectively, it links fine.
      >
      > I don't know what else to try, any ideas is welcome.
      >
      > Benoit Grimard[/color]

      Can you show us the exact commands you are using to compile and link,
      and the exact error message you are getting?

      Comment

      • Ben

        #4
        Re: ANSI C Compilation linking problem

        john_bode@my-deja.com wrote in message news:<111996607 0.691400.78470@ f14g2000cwb.goo glegroups.com>. ..[color=blue]
        > Ben wrote:[color=green]
        > > I get an error when the compilator tries to link the object files of
        > > my program. I have the files group.h and group.c that use a struct
        > > define in logic.h and two fonctions define in logic.c.
        > >
        > > The program compile group.o fine, but when trying to link, I get an
        > > error in group.h saying that a struct that is defined in logic.h
        > > cannot be found. Include logic.h is explicitly call in group.h because
        > > it used an instance of that struct. What I dont understand is how,
        > > when the program compile, it is able to find the reference to the
        > > struct in logic, but when he tries to link, he does not find it
        > > anymore.
        > >
        > > If I take all the code from logic.h and logic.c and I copy it in
        > > group.h and group.c respectively, it links fine.
        > >
        > > I don't know what else to try, any ideas is welcome.
        > >
        > > Benoit Grimard[/color]
        >
        > Can you show us the exact commands you are using to compile and link,
        > and the exact error message you are getting?[/color]


        The ANSI-C code Im writing is to be run on opentv middleware platform,
        and it just ended up that modified GNU compiler didnt catch an error
        while making logic.o. I think because it postponed the definition of a
        pointer to a struct because the include for that struct was missing.
        So the logic.o wasnt really compile and he forgot that it wasnt
        complete and still tryed to link it. So, he wasnt able to find the
        struct in the not complete logic.o, so it gave me an error in group.h.
        I have yet to understand why the compiler didnt catch that or write an
        error code on the good object at least.

        ^^^^^^
        I have include the file which contain the struct and it compile and
        link fine, this is just a guess of what I think happened.

        It was my fault after all, but the compiler didnt helped me to find
        the error at all.

        Comment

        • Joe Wright

          #5
          Re: ANSI C Compilation linking problem

          Ben wrote:[color=blue]
          > john_bode@my-deja.com wrote in message news:<111996607 0.691400.78470@ f14g2000cwb.goo glegroups.com>. ..
          >[color=green]
          >>Ben wrote:
          >>[color=darkred]
          >>>I get an error when the compilator tries to link the object files of
          >>>my program. I have the files group.h and group.c that use a struct
          >>>define in logic.h and two fonctions define in logic.c.
          >>>
          >>>The program compile group.o fine, but when trying to link, I get an
          >>>error in group.h saying that a struct that is defined in logic.h
          >>>cannot be found. Include logic.h is explicitly call in group.h because
          >>>it used an instance of that struct. What I dont understand is how,
          >>>when the program compile, it is able to find the reference to the
          >>>struct in logic, but when he tries to link, he does not find it
          >>>anymore.
          >>>
          >>>If I take all the code from logic.h and logic.c and I copy it in
          >>>group.h and group.c respectively, it links fine.
          >>>
          >>>I don't know what else to try, any ideas is welcome.
          >>>
          >>>Benoit Grimard[/color]
          >>
          >>Can you show us the exact commands you are using to compile and link,
          >>and the exact error message you are getting?[/color]
          >
          >
          >
          > The ANSI-C code Im writing is to be run on opentv middleware platform,
          > and it just ended up that modified GNU compiler didnt catch an error
          > while making logic.o. I think because it postponed the definition of a
          > pointer to a struct because the include for that struct was missing.
          > So the logic.o wasnt really compile and he forgot that it wasnt
          > complete and still tryed to link it. So, he wasnt able to find the
          > struct in the not complete logic.o, so it gave me an error in group.h.
          > I have yet to understand why the compiler didnt catch that or write an
          > error code on the good object at least.
          >
          > ^^^^^^
          > I have include the file which contain the struct and it compile and
          > link fine, this is just a guess of what I think happened.
          >
          > It was my fault after all, but the compiler didnt helped me to find
          > the error at all.[/color]

          Most of my C programming involves only one 'source.c' file. As soon as I
          have two translation units, I do compiles with 'make' and a carefully
          constructed makefile. It saves a lot of time.

          --
          Joe Wright
          "Everything should be made as simple as possible, but not simpler."
          --- Albert Einstein ---

          Comment

          Working...