Skip to main content
Improved wording
Source Link
kzidane
  • 17.8k
  • 3
  • 30
  • 103

A library's header file (the one that endsends with the .h extension) doesn't contain function definitions. Instead, itIt contains the library's resources that are available for you to use. These resources includethings like:

  1. Functionfunction declarations (aka prototypes).
  2. Variables.
  3. Structs.variables
  4. Typestructs and type definitions.

For more information, you may have a look at thisSee answerthis answer and watch the shortthis short on libraries - week 1!for more info.

To use a library, you haveneed to do 2 things:

  1. To include the library's header file usingin which the functions, types, variables, etc you'd like to use are declared

    a. In caseif the header file is already in one of the default include directorydirectories that are searched during preprocessing (i.e.g., /usr/include/) we, use:

    #include <filename.h> 

    b. In case the header is not in the default include directoryotherwise (e.g., in case it's inif the header file is in same directory as the source code file or in another directory), we use:

    #include "filename.h" 
  2. To link the library's binary code with the binary code ofto your program using the -l[library name]. For exampleE.g., to link the cs50 library, you may to compile your program like thatshould run:

    clang prog.c -lcs50 -o prog 

NoticeNote that make on the applianceCS50 Appliance automatically links the cs50 library by defaultfor you. So you maycould just run:

make prog 

A library's header file (the one that ends with the .h extension) doesn't contain function definitions. Instead, it contains the library's resources that are available for you to use. These resources include

  1. Function declarations (aka prototypes).
  2. Variables.
  3. Structs.
  4. Type definitions.

For more information, you may have a look at this answer and watch the short on libraries - week 1!

To use a library, you have to do 2 things

  1. To include the library's header file using

    a. In case the header file is in the default include directory (i.e., /usr/include/) we use

    #include <filename.h> 

    b. In case the header is not in the default include directory (e.g., in case it's in the same directory as the source code file or in another directory), we use

    #include "filename.h" 
  2. To link the library's binary code with the binary code of your program using the -l[library name]. For example, to link the cs50 library, you may to compile your program like that

    clang prog.c -lcs50 -o prog 

Notice that make on the appliance links the cs50 library by default. So you may just run

make prog 

A library's header file (ends with the .h) doesn't contain function definitions. It contains things like:

  1. function declarations (aka prototypes)
  2. variables
  3. structs and type definitions

See this answer and watch this short for more info.

To use a library, you need to do 2 things:

  1. include header file in which the functions, types, variables, etc you'd like to use are declared

    a. if the header file is already in one of the directories that are searched during preprocessing (e.g., /usr/include/), use:

    #include <filename.h> 

    b. otherwise (e.g., if the header file is in same directory as the source code file), use:

    #include "filename.h" 
  2. link the library's binary code to your program using -l[library name]. E.g., to link the cs50 library, you should run:

    clang prog.c -lcs50 -o prog 

Note that make on the CS50 Appliance automatically links the cs50 library for you. So you could just run:

make prog 
replaced http://cs50.stackexchange.com/ with https://cs50.stackexchange.com/
Source Link

A library's header file (the one that ends with the .h extension) doesn't contain function definitions. Instead, it contains the library's resources that are available for you to use. These resources include

  1. Function declarations (aka prototypes).
  2. Variables.
  3. Structs.
  4. Type definitions.

For more information, you may have a look at this answeranswer and watch the short on libraries - week 1!

To use a library, you have to do 2 things

  1. To include the library's header file using

    a. In case the header file is in the default include directory (i.e., /usr/include/) we use

    #include <filename.h> 

    b. In case the header is not in the default include directory (e.g., in case it's in the same directory as the source code file or in another directory), we use

    #include "filename.h" 
  2. To link the library's binary code with the binary code of your program using the -l[library name]. For example, to link the cs50 library, you may to compile your program like that

    clang prog.c -lcs50 -o prog 

Notice that make on the appliance links the cs50 library by default. So you may just run

make prog 

A library's header file (the one that ends with the .h extension) doesn't contain function definitions. Instead, it contains the library's resources that are available for you to use. These resources include

  1. Function declarations (aka prototypes).
  2. Variables.
  3. Structs.
  4. Type definitions.

For more information, you may have a look at this answer and watch the short on libraries - week 1!

To use a library, you have to do 2 things

  1. To include the library's header file using

    a. In case the header file is in the default include directory (i.e., /usr/include/) we use

    #include <filename.h> 

    b. In case the header is not in the default include directory (e.g., in case it's in the same directory as the source code file or in another directory), we use

    #include "filename.h" 
  2. To link the library's binary code with the binary code of your program using the -l[library name]. For example, to link the cs50 library, you may to compile your program like that

    clang prog.c -lcs50 -o prog 

Notice that make on the appliance links the cs50 library by default. So you may just run

make prog 

A library's header file (the one that ends with the .h extension) doesn't contain function definitions. Instead, it contains the library's resources that are available for you to use. These resources include

  1. Function declarations (aka prototypes).
  2. Variables.
  3. Structs.
  4. Type definitions.

For more information, you may have a look at this answer and watch the short on libraries - week 1!

To use a library, you have to do 2 things

  1. To include the library's header file using

    a. In case the header file is in the default include directory (i.e., /usr/include/) we use

    #include <filename.h> 

    b. In case the header is not in the default include directory (e.g., in case it's in the same directory as the source code file or in another directory), we use

    #include "filename.h" 
  2. To link the library's binary code with the binary code of your program using the -l[library name]. For example, to link the cs50 library, you may to compile your program like that

    clang prog.c -lcs50 -o prog 

Notice that make on the appliance links the cs50 library by default. So you may just run

make prog 
Source Link
kzidane
  • 17.8k
  • 3
  • 30
  • 103

A library's header file (the one that ends with the .h extension) doesn't contain function definitions. Instead, it contains the library's resources that are available for you to use. These resources include

  1. Function declarations (aka prototypes).
  2. Variables.
  3. Structs.
  4. Type definitions.

For more information, you may have a look at this answer and watch the short on libraries - week 1!

To use a library, you have to do 2 things

  1. To include the library's header file using

    a. In case the header file is in the default include directory (i.e., /usr/include/) we use

    #include <filename.h> 

    b. In case the header is not in the default include directory (e.g., in case it's in the same directory as the source code file or in another directory), we use

    #include "filename.h" 
  2. To link the library's binary code with the binary code of your program using the -l[library name]. For example, to link the cs50 library, you may to compile your program like that

    clang prog.c -lcs50 -o prog 

Notice that make on the appliance links the cs50 library by default. So you may just run

make prog