Include header file problem !! on ANSI - C

Discussion in 'C Programming' started by alan, Aug 21, 2003.

  1. alan

    alan Guest

    Dear all,

    I have written my own function by C. And my development platform is
    W2k with VC6.0.
    Then I also defined a header file to extern declare this function.
    After that, I include this header file.

    The function is stored in C:\temp\myfun.c
    int func(){
    return 1;
    }

    The header file is stored in C:\temp\myheader.h
    extern int func(void);


    in my main program, I got a problem if I include this header file
    (myheader.h).
    #include <stdio.h>
    #include "C:\temp\myheader.h"

    void main(){
    func();
    }

    This main program is not in c:\temp\ folder.
    The error message is {
    --------------------Configuration: pureC_test - Win32
    Debug--------------------
    Compiling...
    main.c
    Linking...
    main.obj : error LNK2001: unresolved external symbol _func
    Debug/pureC_test.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.
    Creating browse info file...

    pureC_test.exe - 2 error(s), 0 warning(s)

    }

    BUT if I copy the myfun.c & myheader.h in the same path as the main
    program. It works fine.

    Can anybody help me to solve this problem??

    Thank you very much.
    Alan
     
    alan, Aug 21, 2003
    #1
    1. Advertising

  2. alan

    CBFalconer Guest

    alan wrote:
    >

    .... snip ...
    >
    > The function is stored in C:\temp\myfun.c
    > int func(){
    > return 1;
    > }
    >
    > The header file is stored in C:\temp\myheader.h
    > extern int func(void);
    >
    > in my main program, I got a problem if I include this header file
    > (myheader.h).
    > #include <stdio.h>
    > #include "C:\temp\myheader.h"


    Those backslashes are escape characters. \t means a tab char. \m
    is not defined, but most likely is taken as m. Either use forward
    slashes, or double the backslashes.

    .... snip ...
    >
    > Can anybody help me to solve this problem??


    --
    Chuck F () ()
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net> USE worldnet address!
     
    CBFalconer, Aug 21, 2003
    #2
    1. Advertising

  3. alan

    Randy Howard Guest

    In article <>,
    says...
    > in my main program, I got a problem if I include this header file
    > (myheader.h).
    > #include <stdio.h>
    > #include "C:\temp\myheader.h"


    This is all off-topic for CLC, which only talks about the standard
    C language, not compiler-specific build environments and their
    problems. One of the microsoft newsgroups is probably your best
    bet.

    However... Using VC, without an external make file, the usual way of
    doing this is to add the directory to your include path in the
    project itself, then simply use
    #include "myhdeader.h"

    >
    > void main(){
    > func();
    > }
    >
    > This main program is not in c:\temp\ folder.
    > The error message is {
    > --------------------Configuration: pureC_test - Win32
    > Debug--------------------
    > Compiling...
    > main.c
    > Linking...


    Notice, it never compiled myfun.c. That's because the source file also
    must be added to the project. The unresolved external is due to there
    not being an object file containing func(). Add the source file, do
    a build all, and you should be good to go.
     
    Randy Howard, Aug 21, 2003
    #3
  4. alan

    W.Paure Guest

    CBFalconer <> wrote in message news:<>...
    > alan wrote:
    > >

    > ... snip ...
    > >
    > > The function is stored in C:\temp\myfun.c
    > > int func(){
    > > return 1;
    > > }
    > >
    > > The header file is stored in C:\temp\myheader.h
    > > extern int func(void);
    > >
    > > in my main program, I got a problem if I include this header file
    > > (myheader.h).
    > > #include <stdio.h>
    > > #include "C:\temp\myheader.h"

    >
    > Those backslashes are escape characters. \t means a tab char. \m
    > is not defined, but most likely is taken as m. Either use forward
    > slashes, or double the backslashes.

    It's true.In addition,the content of 'myheader.h' should be
    int func(void);
    The word of extern isn't needed.
    >
    > ... snip ...
    > >
    > > Can anybody help me to solve this problem??
     
    W.Paure, Aug 21, 2003
    #4
  5. alan

    Eric Sosman Guest

    CBFalconer wrote:
    >
    > alan wrote:
    > >

    > ... snip ...
    > >
    > > The function is stored in C:\temp\myfun.c
    > > int func(){
    > > return 1;
    > > }
    > >
    > > The header file is stored in C:\temp\myheader.h
    > > extern int func(void);
    > >
    > > in my main program, I got a problem if I include this header file
    > > (myheader.h).
    > > #include <stdio.h>
    > > #include "C:\temp\myheader.h"

    >
    > Those backslashes are escape characters. \t means a tab char. \m
    > is not defined, but most likely is taken as m. Either use forward
    > slashes, or double the backslashes.


    Nit-pick: The backslashes are *not* escape sequences,
    and \t does *not* mean a tab character. The stuff between
    the double quotes is a "q-char-sequence," *not* a string
    literal.

    6.4.7 Header names
    /3/ [...] Similarly, if the characters ', \, //, or /*
    occur in the sequnce between the " delimiters, the
    behavior is undefined(68)

    68) Thus, sequences of characters that resemble escape
    sequences cause undefined behavior.

    The practical consequence is that the form of header names
    is platform-dependent, and it's up to the platform to decide
    what (if anything) to do with backslashes and the like. The
    O.P.'s compiler may or may not accept them -- and doubling
    the backslashes may or may not cure the problem.

    --
     
    Eric Sosman, Aug 21, 2003
    #5
  6. alan

    alan Guest

    sorry, I made a type mistake on path slash char.
    I repeat my question.

    I defined a header file to extern declare this function.
    After that, I include this header file.

    The function is stored in C:\\temp\\myfun.c
    int func(){
    return 1;
    }

    The header file is stored in C:\\temp\\myheader.h
    extern int func(void);


    in my main program, I got a problem if I include this header file
    (myheader.h).
    #include <stdio.h>
    #include "C:\\temp\\myheader.h"

    void main(){
    func();
    }

    The main program , say "main.c" is stored in another location.
    But if I copy the myfunc.c & myheader.h to the same path of "main.c",
    it works fine.

    My question is why my main.c program cannot locate "myfunc.c" & "myheader.h" file ??

    Can anybody help me?

    Pls help!!

    Thank you very much.



    Randy Howard <> wrote in message news:<>...
    > In article <>,
    > says...
    > > in my main program, I got a problem if I include this header file
    > > (myheader.h).
    > > #include <stdio.h>
    > > #include "C:\temp\myheader.h"

    >
    > This is all off-topic for CLC, which only talks about the standard
    > C language, not compiler-specific build environments and their
    > problems. One of the microsoft newsgroups is probably your best
    > bet.
    >
    > However... Using VC, without an external make file, the usual way of
    > doing this is to add the directory to your include path in the
    > project itself, then simply use
    > #include "myhdeader.h"
    >
    > >
    > > void main(){
    > > func();
    > > }
    > >
    > > This main program is not in c:\temp\ folder.
    > > The error message is {
    > > --------------------Configuration: pureC_test - Win32
    > > Debug--------------------
    > > Compiling...
    > > main.c
    > > Linking...

    >
    > Notice, it never compiled myfun.c. That's because the source file also
    > must be added to the project. The unresolved external is due to there
    > not being an object file containing func(). Add the source file, do
    > a build all, and you should be good to go.
     
    alan, Aug 22, 2003
    #6
  7. alan

    Randy Howard Guest

    In article <>,
    says...
    > My question is why my main.c program cannot locate "myfunc.c" & "myheader.h" file ??
    >
    > Can anybody help me?
    >
    > Pls help!!



    I already answered your question, included in the quoted text of your
    reply. I give up.
     
    Randy Howard, Aug 22, 2003
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Aguilar, James
    Replies:
    2
    Views:
    726
    Aguilar, James
    Jul 16, 2004
  2. Andreas Bogenberger
    Replies:
    3
    Views:
    1,010
    Andreas Bogenberger
    Feb 22, 2008
  3. Replies:
    1
    Views:
    520
  4. Replies:
    11
    Views:
    1,122
    Keith Thompson
    Apr 28, 2008
  5. Frank Iannarilli

    pre-ansi to ansi c++ conversion?

    Frank Iannarilli, Jul 21, 2009, in forum: C++
    Replies:
    2
    Views:
    442
Loading...

Share This Page