can't compile!

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

    can't compile!

    Hi,

    I know this is not a compiler newsgroup but I really can't find an
    answer to this anwhere and it's very very trivial (I'm sure).

    I have a few files: file1.h, file1.cpp, file2.cpp

    file1.h has a class with a few functions. Now when I try to compile and
    then link the files, the linker says that it can't find a reference to a
    function defined in file1.h!! Why!! I have two object files: file1.o and
    file2.o. Why can't it find a reference from file1.o when the file is in
    the same directory? Please help!

    Steve

    ------------ And now a word from our sponsor ------------------
    Want to have instant messaging, and chat rooms, and discussion
    groups for your local users or business, you need dbabble!
    -- See http://netwinsite.com/sponsor/sponsor_dbabble.htm ----
  • Jorge Rivera

    #2
    Re: can't compile!

    Steve wrote:[color=blue]
    > I have a few files: file1.h, file1.cpp, file2.cpp[/color]
    Withouth being specific, it's hard to tell what's really going on.
    [color=blue]
    > file1.h has a class with a few functions. Now when I try to compile and
    > then link the files, the linker says that it can't find a reference to a
    > function defined in file1.h!! Why!! I have two object files: file1.o and
    > file2.o. Why can't it find a reference from file1.o when the file is in
    > the same directory? Please help!
    >[/color]
    Look at all the function signatures in file1.h, and make sure that every
    function is defined in either file1.cpp or file2.cpp. What your
    compiler is telling you is that neither file1.o nor file2.o have the
    definition to a function defined in file1.h.

    Jorge L.

    Comment

    • Steve

      #3
      Re: can't compile!



      Jorge Rivera wrote:[color=blue]
      > Steve wrote:
      >[color=green]
      >> I have a few files: file1.h, file1.cpp, file2.cpp[/color]
      >
      > Withouth being specific, it's hard to tell what's really going on.
      >[color=green]
      >> file1.h has a class with a few functions. Now when I try to compile
      >> and then link the files, the linker says that it can't find a
      >> reference to a function defined in file1.h!! Why!! I have two object
      >> files: file1.o and file2.o. Why can't it find a reference from file1.o
      >> when the file is in the same directory? Please help!
      >>[/color]
      > Look at all the function signatures in file1.h, and make sure that every
      > function is defined in either file1.cpp or file2.cpp. What your
      > compiler is telling you is that neither file1.o nor file2.o have the
      > definition to a function defined in file1.h.
      >
      > Jorge L.[/color]

      Thanks Jorge. I just discovered that adding 'inline' to a function that
      is in a separate file becomes inaccessible to other files! Is that
      normal? After I Removed 'inline' from all functions, everything started
      to work fine.


      Cheers,
      Steve

      Comment

      • John Harrison

        #4
        Re: can't compile!

        >[color=blue]
        > Thanks Jorge. I just discovered that adding 'inline' to a function that
        > is in a separate file becomes inaccessible to other files! Is that
        > normal? After I Removed 'inline' from all functions, everything started
        > to work fine.
        >[/color]

        Yes its normal. Put inline functions in header files, the compiler can't
        inline a function unless it can see its definition at the point of use.
        Putting inline functions in a header file is a simple way to make sure this
        is so.

        john


        Comment

        • Michiel Salters

          #5
          Re: can't compile!

          Steve <nospam@nopes > wrote in message news:<40b15612$ 1@clarion.carno .net.au>...[color=blue]
          > Hi,
          >
          > I know this is not a compiler newsgroup but I really can't find an
          > answer to this anwhere and it's very very trivial (I'm sure).
          >
          > I have a few files: file1.h, file1.cpp, file2.cpp
          >
          > file1.h has a class with a few functions. Now when I try to compile and
          > then link the files, the linker says that it can't find a reference to a
          > function defined in file1.h!![/color]

          Post code. We're not psychic.

          Ok, a bit. Perhaps

          // file1.h
          class C
          {
          void foo();
          };
          // file1.cpp
          void foo(); // new function, not void C::foo()

          Regards,
          Michiel Salters

          Comment

          Working...