c - 通过头文件查找库

标签 c linux

我想编译以下简单的 syslog 日志记录程序:

#include <syslog.h>

setlogmask (LOG_UPTO (LOG_NOTICE));

openlog ("exampleprog", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);

syslog (LOG_NOTICE, "Program started by User %d", getuid ());
syslog (LOG_INFO, "A tree falls in a forest");

closelog ();

我知道 syslog.h 的位置,但我如何知道 syslog 的库名称和位置以告诉编译器链接到?有没有一种通用的方法可以找到带有头文件声明定义的库(例如,在什么库中 abc.h 中声明的函数 x 定义(主体))?

最佳答案

syslog() 在 C 库中定义,默认情况下您的编译器将链接到它。 在我的系统上,假设您的编译器是 gcc,您可以看到使用 gcc -v file.c -o file.o 调用的默认编译器参数。强调 -v 开关。

在 C 库上调用 nm 得到:

nm -D /lib/x86_64-linux-gnu/libc.so.6 | grep syslog
00000000000fffd0 T syslog

关于c - 通过头文件查找库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57962324/

相关文章:

linux - 如何将两个文件夹区分为多个补丁文件

c - 如何处理将 usize 传递给需要 uint32_t 的 C 函数?

c - 如何在我的程序中检测到 stdout 已关闭(当 telnet session 关闭时)?

c++ - 获取 unicode 代码点的大写或小写(如 uint32_t)

C++套接字,客户端无法向java服务器发送消息

linux - Tor 浏览器 bundle 无法建立连接

c - 需要帮助在控制台应用程序中使用 Windows API 在 C 中创建我自己的 getch() 函数

c - 定点处理 : what is the difference between uint16_t and uint_fast16_t?

linux - mktemp 的问题

linux - 在 linux 终端中,告诉我我在哪个文件夹中的命令是什么?