小白问下,怎么知道用到的函数需要连接什么库?

guolisen 2013-01-22 08:28:08
小白问下,怎么知道用到的函数需要连接什么库?

经常用到一些函数,找不到定义,又不知道怎么找有时候查man也查不到,请问有什么办法知道函数用的什么库吗?比如clock(),gettimeofday()
...全文
225 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
szqh97 2013-02-06
  • 打赏
  • 举报
回复
man strcmp 这样的啊
子谋 2013-02-06
  • 打赏
  • 举报
回复
man page 如果man也查不到 就google一下…… 一般第一个就是kernel.org,或者是其他的手册……
疯疯癫癫 2013-01-23
  • 打赏
  • 举报
回复
2楼正解 不过有时如果有同名的终端命令也是这个函数名时,直接man看到的是命令而不是函数 如:man mkdir 看到的是 mkdir 命令而不是函数,看mkdir的函数应该这样 man 2 mkdir
luo6620378xu 2013-01-23
  • 打赏
  • 举报
回复
你man不到相应的函数说明,可能是对应的man手册没有安装: sudo apt-get install manpages-dev // C API sudo apt-get install manpages-posix // posix function sudo apt-get install manpages-posix-dev // posix develop documents sudo apt-get install glibc-doc // C API sudo apt-get install stl-manual // STL sudo apt-get install libstdc++6-4.1-doc//C++
luo6620378xu 2013-01-23
  • 打赏
  • 举报
回复
引用 5 楼 fengfengdiandia 的回复:
2楼正解 不过有时如果有同名的终端命令也是这个函数名时,直接man看到的是命令而不是函数 如:man mkdir 看到的是 mkdir 命令而不是函数,看mkdir的函数应该这样 man 2 mkdir
比如: clock函数的说明在3 section man 3 clock
luo6620378xu 2013-01-23
  • 打赏
  • 举报
回复
引用 5 楼 fengfengdiandia 的回复:
2楼正解 不过有时如果有同名的终端命令也是这个函数名时,直接man看到的是命令而不是函数 如:man mkdir 看到的是 mkdir 命令而不是函数,看mkdir的函数应该这样 man 2 mkdir
这是因为man的section不一样
fdl19881 2013-01-23
  • 打赏
  • 举报
回复
当然有时候man查不到。一般是因为没安装相应的manpage doc. http://manpages.ubuntu.com/ 可以在这个网上看。 如: precise (3) pthread_create.3.gz Provided by: manpages-dev_3.35-0.1ubuntu1_all NAME pthread_create - create a new thread 所以你可以安装sudo apt-get install manpages-dev_3.35-0.1ubuntu1_all就有了。
fdl19881 2013-01-23
  • 打赏
  • 举报
回复
程序一般默认链接libc,,所以上面的不用指定。 再比如man pthread_create NAME pthread_create - create a new thread SYNOPSIS #include <pthread.h> int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg); Compile and link with -pthread. DESCRIPTION The pthread_create() function starts a new thread in the calling process. The new thread starts execution by invoking start_routine(); arg is passed as the sole argument of start_routine().
fdl19881 2013-01-23
  • 打赏
  • 举报
回复
ubuntu下用man命令就能查看到。 比如man gettimeofday NAME gettimeofday, settimeofday -- get/set date and time LIBRARY Standard C Library (libc, -lc) SYNOPSIS #include <sys/time.h> int gettimeofday(struct timeval *tp, struct timezone *tzp); int settimeofday(const struct timeval *tp, const struct timezone *tzp); DESCRIPTION Note: timezone is no longer used; this information is kept outside the kernel. 别的linux下应该也写了使用哪个库的吧。你看看。
xxjnetwork 2013-01-22
  • 打赏
  • 举报
回复
我目前用的eclipse+c插件,挺好用的,就算你没有include,也依旧可以ctrl+右键点过去,然后就知道了。当然查资料应该还是有的吧,这是我目前的笨办法

23,124

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧