dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: difference between including header file and shared library.

  1. #1
    Join Date
    Mar 2005
    Posts
    55

    difference between including header file and shared library.

    Hi,

    What is the difference between including header file (.h) and including shared library (.so) in C++ code?

    Thanks.

  2. #2
    Join Date
    Aug 2002
    Location
    Cluj-Napoca,Romania
    Posts
    3,496

    Re: difference between including header file and shared library.

    They served different purposes. You still need to include the header file, unless you want to use the library manually ( by finding function addresses and invoking them).
    Har Har

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

    Re: difference between including header file and shared library.

    A static or shared library contains definitions. A header file may only contain declarations. A header file *could* also contain definitions, but it usually won't.

    Thus a header file is required for the code you write to know *how* to use 3rd-party code. A static or shared library is required for that 3rd-party code to know what to do.

  4. #4
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: difference between including header file and shared library.

    You must include header file. Comparing header file with shared object/library makes no sense.

    As you know, CPP files contain actual code. But that is source code. The .SO files contain binary code (linkable code). Here we can compare .CPP files with .SO files.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  5. #5
    Join Date
    Apr 2008
    Posts
    6

    Re: difference between including header file and shared library.

    usually header files contains declarations and SO files are the compiled version of the code which can be linked Statically or Dynamically to your executable

  6. #6
    Join Date
    Aug 2002
    Location
    Cluj-Napoca,Romania
    Posts
    3,496

    Re: difference between including header file and shared library.

    Quote Originally Posted by Lindley
    Thus a header file is required for the code you write to know *how* to use 3rd-party code.
    That's not necessarily true. You can use a dynamic function library ( dll) without a header file but it is not the best/easiest way to do it.
    Har Har

  7. #7
    Join Date
    Aug 2005
    Location
    LI, NY
    Posts
    576

    Re: difference between including header file and shared library.

    Quote Originally Posted by PadexArt
    That's not necessarily true. You can use a dynamic function library ( dll) without a header file but it is not the best/easiest way to do it.
    This kind of goes into a debate over semantics. One could argue that only by including a header does your code have knowledge of how to use the library, while when using LoadLibrary/GetProcAddress you rely on an assumption of how to use the library. Saying that code knows something implies to me compile-time knowledge.
    - Alon

  8. #8
    Join Date
    Aug 2002
    Location
    Cluj-Napoca,Romania
    Posts
    3,496

    Re: difference between including header file and shared library.

    Quote Originally Posted by Hermit
    This kind of goes into a debate over semantics. One could argue that only by including a header does your code have knowledge of how to use the library, while when using LoadLibrary/GetProcAddress you rely on an assumption of how to use the library. Saying that code knows something implies to me compile-time knowledge.
    Yes, that's why I said it's not necessarily true. You can get away using a library without a header file, and at times that is the only way you can do things. An example for that is checking if a library supports a function (WinAPI usage).
    Har Har

  9. #9
    Join Date
    Mar 2005
    Posts
    55

    Re: difference between including header file and shared library.

    Thanks a lot everybody.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)