473,320 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 ----
Jul 22 '05 #1
4 1044
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


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
>
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: zhouhaiming | last post by:
On our test machine I can compile my c source code on AIX5.1(ML4) by "- q32" option and "OBJECT_MODE=32" environment variable, and it can correctly running. My operation system environment is:...
0
by: Jordan Willms | last post by:
My xsl stylesheet is as simple as follows: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet xmlns:ims="http://www.imsglobal.org/xsd/imsmd_v1p2"...
8
by: Davy | last post by:
Hi all, I use VC and gcc/gdb to compile and debug C/C++ files. But I found some of the debug version of the compiled files are too large to be run in a small RAM. Can I compile C/C++ Debug...
7
by: alphatan | last post by:
Is there relative source or document for this purpose? I've searched the index of "Mastering Regular Expression", but cannot get the useful information for C. Thanks in advanced. -- Learning...
4
by: Chronologic | last post by:
All, I have an issue I would like some expert help on. I understand, or so I believe, that C# does not support the concept of a "compile time macro". At least not in the sense I'm looking...
10
by: Jordan | last post by:
I would like to take my ASP.NET project to another computer, which doesn't have Visual Studio. If I modify the code there, is there a way to recompile it without Visual Studio? Thanks!
5
by: MLH | last post by:
A97 aborts creation of MDE reporting that there's a compile error in one form. Sure enough, if I remove the form from the source database and attempt to compile the MDE, it succeeds. But when I...
12
by: Ark | last post by:
Hello NG, I arrange data in structs like { members... uint16_t crc; more members, maybe... } Then I need to save them, up to and including crc, in non-volatile memory or a file, as the case...
15
by: steve yee | last post by:
i want to detect if the compile is 32 bits or 64 bits in the source code itself. so different code are compiled respectively. how to do this?
3
by: NvrBst | last post by:
Right now I have C99 code in .c extensions. I compile it in VSC++ and it complains about a lot of errors. I change the extensions to .cpp and compile in VSC++ and it succeeds. Is there a way...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.