By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,778 Members | 1,957 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,778 IT Pros & Developers. It's quick & easy.

can't compile!

P: n/a
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 ----
Jul 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.
Jul 22 '05 #2

P: n/a


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

Jul 22 '05 #3

P: n/a
>
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
Jul 22 '05 #4

P: n/a
Steve <nospam@nopes> wrote in message news:<40********@clarion.carno.net.au>...
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
Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.