can't compile!

S

Steve

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

Jorge Rivera

Steve said:
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.
 
S

Steve

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

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
 
J

John Harrison

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
 
M

Michiel Salters

Steve said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top