-
May 19th, 2008, 08:08 AM
#1
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.
-
May 19th, 2008, 08:16 AM
#2
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
-
May 19th, 2008, 09:34 AM
#3
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.
-
May 19th, 2008, 11:32 AM
#4
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.
-
May 19th, 2008, 11:44 AM
#5
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
-
May 19th, 2008, 01:15 PM
#6
Re: difference between including header file and shared library.
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
-
May 19th, 2008, 01:24 PM
#7
Re: difference between including header file and shared library.
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
-
May 19th, 2008, 01:28 PM
#8
Re: difference between including header file and shared library.
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
-
May 21st, 2008, 11:36 AM
#9
Re: difference between including header file and shared library.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|