CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Apr 2005
    Posts
    1,828

    Linking Headers and Source

    I am using VS2005 development environment.
    I have an existing source code which takes a lot of header files as well as source and library files

    Code:
    D:\..\SRC\C++\MyProject\srclib
    All the include and source files lies within the sub folder of this folder

    Include file directories
    Code:
    D:\..\SRC\C++\MyProject\srclib\apr\include
    D:\..\SRC\C++\MyProject\srclib\apr-iconv\include
    D:\..\SRC\C++\MyProject\srclib\apr-util\include
    Similarly there are library files as well as source files that reside within this scrlib too.

    Now the problem is specifying the path of these folders so that the compiler is able to find the header files therefore the function signature

    Now one way is to include these directories in "Tools>Options>Project & Solution>VC++ Directories".

    Or we go to "project settings and in General>C/C++>additional Include Directories", specify the settings.

    I choosed the 2nd option for include directory.

    Code:
    ./include
    ./srclib/apr/include
    ./srclib/apr-util/include
    ./srclib/apr/memory/unix
    But the problem that I am facing can be demonstrated with this example.

    "apr_pools.h" contains some important function signatures reside in this location

    Code:
    D:\..\SRC\C++\MyProject\srclib\apr\include
    However its corresponding source file "apr_pools.c" which contains the implementation of those functions reside in this location

    Code:
    D:\..\SRC\C++\MyProject\srclib\apr\momory\unix
    I included this path using "Tools>Options>Project & Solution>VC++ Directories>" and in show directories selected Souce File

    But compiler is unable to find the implementation of the methods that are in apr_pool.h thus generates external unresolved symbol error

    Is there any neat and efficient way of including directories when there are too many complex paths?

    Thanks & Regards,
    Adeel

  2. #2
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    454

    Re: Linking Headers and Source

    we have two Scenario , if your header files have CPP or C files with them then you are placing them wrong area , they not to be included in project include options , they need to be placed in the project file in the left of your project settings, so go to the project folder on the left , and select add existing , header for header folder and sources for sources folder.

    the other option , is header files are accompanied by lib files , then you have selected the right choice , in the include options , all you need to do now is to tell the compiler where the lib files are , since I have not used vs 2005 in a while you can look it up on the web , setting are pretty straight forward.

    Finally when you get unresolved symbols errors , that means linker cannot find the implementations of the function in your header files , cause by default header files only contain the declaration of the functions and data types .

    hope this helps.

  3. #3
    Join Date
    Apr 2005
    Posts
    1,828

    Re: Linking Headers and Source

    Quote Originally Posted by aamir121a View Post
    we have two Scenario , if your header files have CPP or C files with them then you are placing them wrong area , they not to be included in project include options , they need to be placed in the project file in the left of your project settings, so go to the project folder on the left , and select add existing , header for header folder and sources for sources folder.

    the other option , is header files are accompanied by lib files , then you have selected the right choice , in the include options , all you need to do now is to tell the compiler where the lib files are , since I have not used vs 2005 in a while you can look it up on the web , setting are pretty straight forward.

    Finally when you get unresolved symbols errors , that means linker cannot find the implementations of the function in your header files , cause by default header files only contain the declaration of the functions and data types .

    hope this helps.
    yes some header files have their implementation on .c file and some project files have their implementation in .lib files. But this is default settings for these Apache SDKs.


    Now "apr_pool.h" resides in this location which contains the signature

    Code:
    D:\..\SRC\C++\MyProject\srclib\apr\include
    And its corresponding source file "apr_pools.c" which contains the implementation of those functions reside in this location

    Code:
    D:\..\SRC\C++\MyProject\srclib\apr\momory\unix
    Whre is that project file option that you are talking about?

  4. #4
    Join Date
    Jul 2009
    Location
    India
    Posts
    835

    Re: Linking Headers and Source

    ./include
    ./srclib/apr/include
    ./srclib/apr-util/include
    ./srclib/apr/memory/unix

    in windows we used \ for paths instead / so it should be

    .\include
    .\srclib\apr\include
    .\srclib\apr-util\include
    .\srclib\apr\memory\unix

  5. #5
    Join Date
    Apr 2005
    Posts
    1,828

    Re: Linking Headers and Source

    Quote Originally Posted by hypheni View Post
    ./include
    ./srclib/apr/include
    ./srclib/apr-util/include
    ./srclib/apr/memory/unix

    in windows we used \ for paths instead / so it should be

    .\include
    .\srclib\apr\include
    .\srclib\apr-util\include
    .\srclib\apr\memory\unix
    Changed it. Still the result is same

  6. #6
    Join Date
    Apr 2005
    Posts
    1,828

    Re: Linking Headers and Source

    I've tried everything. But the compiler is unable to find the implementation of functions residing this header file.
    Code:
    D:\..\SRC\C++\MyProject\srclib\apr\include\apr_pool.h

    Though their implemenration is available in in this header file
    Code:
    D:\..\SRC\C++\MyProject\srclib\apr\momory\unix\apr_pool.c

  7. #7
    Join Date
    Apr 2008
    Posts
    118

    Re: Linking Headers and Source

    There's always the doomsday option for including headers:

    Code:
    #include "D:\theComplete\directory\structure\SRC\C++\MyProject\srclib\apr\include\apr_pool.h"
    But the compiler is unable to find the implementation of functions residing this header file.
    So you're saying that the implementation (not the definition that usually lives in the header file, but that actual source code that carries out the operations) can't be found? If the implementation exists in a source file (rather than an already compiled library), then your problem is that you're not compiling that source and linking to it. As I recall, under VS there's some kind of "add this source file to the project" option that covers that.
    Last edited by Moschops; February 3rd, 2011 at 06:20 AM.

  8. #8
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    454

    Re: Linking Headers and Source

    this one is for the source file only header with , C or CPP files , place all header and C / CPP files in the same folder , open up the C file in text editor ( not vc) and make sure that include file in those C files is <myheader.h> only and not <path/myhader.h> , then go to all header files and change all include to <myheader.h> and not <path/myheader.h> . now add them through the method I explained , when you are changing the header include path , only change for those which came with the sources , and not the header which are windows default , like iostream or windows.h

    please see attached screen shot as to where to add the header and source file , better still if you like send me the project you are compiling , and I will set it up for you.

    some times the referencing paths inside a C or a header file , do not match
    I have see this a lot in open source project , wxWidgets , or zlib

    you can upload your zip file of the project through

    http://www.sendspace.com

    and post the download link here. PM me the link
    Attached Images Attached Images

  9. #9
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    454

    Re: Linking Headers and Source

    Quote Originally Posted by maverick786us View Post
    I've tried everything. But the compiler is unable to find the implementation of functions residing this header file.
    Code:
    D:\..\SRC\C++\MyProject\srclib\apr\include\apr_pool.h

    Though their implemenration is available in in this header file
    Code:
    D:\..\SRC\C++\MyProject\srclib\apr\momory\unix\apr_pool.c
    from the path , look like apr_pool.h and apr_pool.c are not in the same directory pls . make sure the apr_pool.c include directives are referencing the apr_pool.h properly
    , further looks like may be compiling a unix version , in that case ( VS 2005 ) or any other VS does not support unix header , please make sure that is not the case. you might need cgywin and mingw to compile this , but that is another story.

  10. #10
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    454

    Re: Linking Headers and Source

    here in the link on how to compile apache SDK for win32

    http://httpd.apache.org/docs/1.3/win_compiling.html

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