Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find the header file to be included for a library function in linux

Tags:

c

linux

Given a function, let's say atoi, how can I find the header file I should include if I want to use this function ? I'm always get puzzled for that issue. If let me treat function like "atoi" as linux c api, I can put my question in another way as : Is a document for linux c api ?

like image 979
Haiyuan Zhang Avatar asked Mar 03 '10 21:03

Haiyuan Zhang


People also ask

Where can I find header files in linux?

Most standard headers are stored in /usr/include . It looks like stdbool. h is stored somewhere else, and depends on which compiler you are using. For example, g++ stores it in /usr/include/c++/4.7.

How do you check if a header file is included?

To check if an header file has been included or not in a C or C++ code, we need to check if the macro defined in the header file is being defined in the client code. Standard header files like math. h have their own unique macro (like _MATH_H ) which we need to check. Consider this example of checking if math.

Which header file include a function?

The stdarg. h header file includes a function for the variable number of arguments.

What is header file and library function?

1. Definition. Header File is the file where all the headers name are mentioned that going to be used or consumed in the main code file. On other hand Library is the file where the implementation code of each header is written down which is mentioned in the Header file.


1 Answers

Man pages. Type man atoi (or, in general, man <function>) at your command prompt. It will give you usage information as well as a listing of which headers to include.

Man pages also document programs and commands (find, grep, cd, etc.). Sometimes you may run into a case where a program has the same name as a C function (e.g. write). In that case, you need to direct man to look in the correct section of the manual, section 2 for system calls and section 3 for library functions. You do this by inserting the section number between "man" and the command name: man 2 write. If you do not know whether a given function is a system call or a library function, try both.

You can learn more about manual pages by typing man man.

like image 90
Tyler McHenry Avatar answered Oct 21 '22 12:10

Tyler McHenry