CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2006
    Posts
    63

    Unhappy How to include my own function source code?

    Presently I copy the .h and .cpp files containing general purpose functions into each project directory, and everything compiles and links nicely. However, if I try to #include the .h file when it is placed in a different directory, I get a the following 2 errors:
    error LNK2001: unresolved external symbol ......
    and
    fatal error LNK1120: 1 unresolved externals

    This occurs if I #include the absolute path, both with and without quoted backslash, and whether or not I add the path to (all sections of ) the Tools:Optionsirectories.

    I can't believe that there is not a way to include source files which are in some user-defined common directory.

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: How to include my own function source code?

    It's not enough to #include the header. That only provides enough information for the compiler to verify the functions in the header are being called properly. In order to actually *use* the functions, you must compile the .cpp as well and link it with your code.

    Either add the .cpp to your project, or compile it into a static library and link it with your project.

    Unresolved external symbol means *exactly* what it says. There's an external symbol (something from the .h file) which the linker can't resolve, because it doesn't have access to the cpp file that defines it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured