473,320 Members | 1,936 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.

Link through Header Files

Hi,

I am having three files similar to the stucture given below, while i
execute my test.c, it show error /test.c:5: undefined reference to
`myfunction'.
I have included myprogram.h in both the files myprogram.c and test.c.

if i comment out the line myfunction from myfunction.h, then it is
working properly. Is it multiple definition error?
i compile the files as
cc -c myprogram.c -o myprogram
cc -c test.c -o test
cc -o test test.o my

Thanks in Advance!
/******* myprogram.c *******/

#include "myprogram.h"
myfunction()
{
}
/******* myprogram.h *******/

myfunction();
/******** test.c *********/
#include "myprogram.h"
int main()
{
myfunction();
}
Jun 27 '08 #1
5 1182
ra******@gmail.com said:
Hi,

I am having three files similar to the stucture given below, while i
execute my test.c, it show error /test.c:5: undefined reference to
`myfunction'.

I have included myprogram.h in both the files myprogram.c and test.c.

if i comment out the line myfunction from myfunction.h, then it is
working properly. Is it multiple definition error?
No - your code has some issues, but it isn't the showstopper in this case.
Rather, it's the way you're invoking the linker.
i compile the files as
cc -c myprogram.c -o myprogram
cc -c test.c -o test
cc -o test test.o my
This can't work, for any reasonable definition of "work".

I suggest you change it, for the time being, to:

cc -c myprogram.c myprogram.o
cc -c test.c -o test.o
cc -o myprogram test.o myprogram.o

<snip>

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 27 '08 #2
ra******@gmail.com wrote:
Hi,

I am having three files similar to the stucture given below, while i
execute my test.c, it show error /test.c:5: undefined reference to
`myfunction'.
I have included myprogram.h in both the files myprogram.c and test.c.

if i comment out the line myfunction from myfunction.h, then it is
working properly. Is it multiple definition error?
i compile the files as
cc -c myprogram.c -o myprogram
cc -c test.c -o test
cc -o test test.o my
Where's myprogram in the line above?
>
/******* myprogram.h *******/

myfunction();
Don't use implicit it return, please.

--
Ian Collins.
Jun 27 '08 #3
Richard Heathfield <rj*@see.sig.invalidwrites:
ra******@gmail.com said:
[...]
>i compile the files as
cc -c myprogram.c -o myprogram
cc -c test.c -o test
cc -o test test.o my

This can't work, for any reasonable definition of "work".

I suggest you change it, for the time being, to:

cc -c myprogram.c myprogram.o
cc -c test.c -o test.o
cc -o myprogram test.o myprogram.o
You missed the "-o" on the first line.

For that matter, the first two commands can be simplified by using the
default output file name:

cc -c myprogram.c
cc -c test.c

though the "-o" does show more explicitly what's going on.

Note that this is about a particular implementation, not about C.
For more details, consult your system's documentation for the "cc"
command, or ask in comp.unix.programmer.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #4
Keith Thompson said:

<snip>
You missed the "-o" on the first line.
So I did.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 27 '08 #5
On Apr 14, 11:04 pm, Richard Heathfield <r...@see.sig.invalidwrote:
Keith Thompson said:

<snip>
You missed the "-o" on the first line.

So I did.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Thanks to everyone! But i found out the problem and fault was mine. i
was trying to invoke a static function from another c file!
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: peetm | last post by:
I'd like to write to a log whenever a visitor to my site downloads a file. So, I'd like the link they click to be to a php 'page' that returns the file. Don't know how to do that! Side...
1
by: deko | last post by:
I use a download script to allow users to download files that are not in a publicly accessible directory. The files should only be downloadable from a secure page which only authenticated users...
4
by: dspohn | last post by:
I am designing a document management system (DMS). The files are stored in a directory on the webserver. The filenames for the documents are stored in a MySQL database. The DMS will track...
5
by: sriram | last post by:
I have the following: class BSA { ... ... ... ... public: enum VRGAttrId {
4
by: firegun9 | last post by:
I am not a newbie C++, but I haven't coded multiple files project under g++. Here is my quesiont: b.h //////////////////// #ifndef b_h #define b_h class b{
10
by: Gary Hughes | last post by:
I'm getting the following error when attempting to link a managed C++ dll. I can't find any reference to these errors with google. Can anyone help? I've included the class definition causing the...
3
by: Paul Cameron | last post by:
Hello, We've recently migrated a very large (40+ projects, 1+ million LOC) VC6 workspace to VC7.1. In general, the compiler and linker are slower. The worst seems to be the release link; under...
14
by: Steve McLellan | last post by:
Hi, Sorry to repost, but this is becoming aggravating, and causing me a lot of wasted time. I've got a reasonably large mixed C++ project, and after a number of builds (but not a constant...
1
by: noleander | last post by:
I need to use a library supplied by someone else: libjpeg.lib. This is a plain C library. I do not have the source code. I do have the header *.h files. When I run dumpbin on the libjpeg.lib,...
18
by: happyvalley | last post by:
a silly question. when linking a program, the path to include files and library files are given already (-I, -L), why still need to give the names of some library by -l , say -lm for math...
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
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.