include directories vs. lib directory concept question

前端 未结 3 949
迷失自我
迷失自我 2021-01-31 03:43

What is the difference between linking to include files versus linking to lib files?

I am fairly new to C/C++ and I\'m having a hard time figuring out the difference be

3条回答
  •  感情败类
    2021-01-31 04:39

    Include files typically contain the declaration of a symbol (a function, a variable). This let's the compiler know that a name is defined (in the header) or elsewhere (in the case of a declaration):

    a.h:
    
    void a_useful_function(); //declaration 
    

    but you can also have a definition:

    a.h:
    
    void a_useful_function()
    {
        //... do something
    }
    

    Libraries are an accumulation of functions which get typically exposed by headers. The header is usually the interface to a library that you will be linking against.

    There exist header only libraries however that have their declarations and definitions code in the same file.

    You mention include directories in your question. The include directories are the places where the compiler searches to resolve an #include "a.h" preprocessor directive.

    But there are also library directories where the linker searches for needed libraries that usually provide implementations (definitions) to the declarations in your headers.

提交回复
热议问题