Re: undefined references to functions when linking



stenasc@xxxxxxxxx writes:

On Jun 12, 6:13 pm, "Joachim Schmitz" <nospam.j...@xxxxxxxxxxxxxxxxxx>
wrote:
<sten...@xxxxxxxxx> schrieb im Newsbeitragnews:1181667898.243965.188770@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> Hi,

In a file test1.c, in have the two functions f1 and f2. These are
declared in the header file t1.h. I want to call these functions in
another file subprog.c, which contains the function call_funcs. I have
included the header file t1.h in subprog.c. Using gcc, I can compile
and get subprog.o without any problems.

However, when I try to link subprog.o into the main application, I get
the errors

In function call_funcs undefined reference to f1
In function call_funcs undefined reference to f2

Anybody have any idea what could be causing this.

You need to compile test1.c too and link the resulting .o with the
subprog.o.

Thanks Jojo...that fixed it...I now get multiple definition
errors...you don't know how to solve that???

A wild guess: t1.h defines (rather than declares) one or more global
variables. I.e. you have "int x;" rather than "extern int x;" in
t1.h. If this is the problem, you need to use the extern form in the
..h file and ensure that only one (you get to chose) compilation unit
contains the actual definition.

--
Ben.
.



Relevant Pages

  • Re: bring an already running app to the front
    ... The most reliable way is to translate the '#define's in the according header ... The name of the header file containing the define is listed in the ... for VB.NET (note that the quality is poor because the declares are based on VB6 declares which often cannot be converted to the right VB.NET declares automatically): ... different .NET programming languages: ...
    (microsoft.public.dotnet.languages.vb)
  • Re: How do I inhibit warning 528?
    ... >> in the header file, then each file that needs it declares ... compiler will type-check no matter how you initialize it. ...
    (comp.lang.c)
  • Re: Linker error - fooView.obj LNK2005: _IID_IProvideTaskPage already defined in fooDoc.obj
    ... Sounds like you have included a header file what declares an IID_ and CLSID_ variable in ... MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)
  • Re: libltdl problem
    ... The header file which declares the class PicData is ... > #included in both module loader and the module. ...
    (comp.os.linux.development.apps)
  • Re: undefined references to functions when linking
    ... included the header file t1.h in subprog.c. ... In function call_funcs undefined reference to f2 ... You need to compile test1.c too and link the resulting .o with the ... Thanks Jojo...that fixed it...I now get multiple definition ...
    (comp.lang.c)