can't compile!

Discussion in 'C++' started by Steve, May 24, 2004.

  1. Steve

    Steve Guest

    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 ----
    Steve, May 24, 2004
    #1
    1. Advertising

  2. Steve

    Jorge Rivera Guest

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

    Withouth being specific, it's hard to tell what's really going on.

    > 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!
    >

    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.
    Jorge Rivera, May 24, 2004
    #2
    1. Advertising

  3. Steve

    Steve Guest

    Jorge Rivera wrote:
    > Steve wrote:
    >
    >> I have a few files: file1.h, file1.cpp, file2.cpp

    >
    > Withouth being specific, it's hard to tell what's really going on.
    >
    >> 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!
    >>

    > 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.


    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
    Steve, May 24, 2004
    #3
  4. >
    > 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.
    >


    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
    John Harrison, May 24, 2004
    #4
  5. Steve <nospam@nopes> wrote in message news:<40b15612$>...
    > 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!!


    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
    Michiel Salters, May 24, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nagaraj
    Replies:
    1
    Views:
    832
    Lionel B
    Mar 1, 2007
  2. timjowers
    Replies:
    7
    Views:
    4,303
    heyjude
    Feb 2, 2011
  3. Replies:
    1
    Views:
    432
    Cowboy \(Gregory A. Beamer\)
    Apr 11, 2008
  4. Carter
    Replies:
    2
    Views:
    488
    Carter
    Mar 4, 2009
  5. fAnSKyer
    Replies:
    2
    Views:
    513
    Alf P. Steinbach
    Jun 7, 2009
Loading...

Share This Page