开发者

Finding where Linux functions are defined

Is there a good database for Linux where I can search for a function n开发者_运维百科ame and it tells me which header it is defined in? Googling doesn't always work for me and there aren't always man pages.


Using manpages

For basic C functions, the manpages should work.

man 2 read
man 3 printf

Section 2 is for system calls (direct to the kernel), and section 3 is for standard C library calls. You can generally omit the section, and man will figure out what you need on its own.

Note that you may need to take extra steps to get development-related manpages on your system. For example, on my Debian system, I had to do apt-get install manpages-dev glibc-doc.

Using library-specific references

For non-basic C functions, you should check the documentation of the library you're using (e.g., GNU's docs for libstdc++, doc.qt.io for Qt, library.gnome.org for GNOME projects like GTK, and so on).

Using the web

linux.die.net is a good online mirror of web pages.

LSB Navigator (as described in this answer) looks cool. I did not know about that.

Using grep

Sometimes it's just easiest to search /usr/include yourself. grep works for this, but ack is much better. For example, if I'm trying to find the header that contains getRootLogger:

cd /usr/include
# Debian calls 'ack' ack-grep.  Your system may differ.
# Add \b before and after to only match a complete word.
ack-grep '\bgetRootLogger\b'

ack will return a nicely formatted and colorized list of matches.

You can wrap this up in a function and put it in your .bashrc file (or equivalent) for easy use:

function findheaderfor() {
  ack-grep \\b$1\\b /usr/include /usr/local/include
}


Try the man pages, I use them a lot. You get the files you need to include. Sometimes you want to pass a section number. Here are some examples :

man 2 socket
man 2 accept
man 3 fopen
man sem_post

2 is for system call related functions
3 is for function from the C library.

If there is no ambiguity, the section number is not needed

If you are looking for kernel function definition or kernel source navigation, you should definitely try lxr.linux.no


Sure, have you tried "man" in Linux?

For C functions, you may want to do "man 3 ".


You could use LSB Navigator (use search field in the top-right corner). However, most functions, about which you will find header information there, have manpages as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜