【发布时间】:2016-04-08 18:03:56
【问题描述】:
我正在尝试制作一个使用命名管道与 Raspberry Pi 3 上的 C++ 程序进行通信的 C 程序。
当我编译我的一些代码时,GCC 正在吐出的警告:
/home/pi/BluetoothTest/btooth.c|76|warning: implicit declaration of function ‘mknod’ [-Wimplicit-function-declaration]|
这是函数的代码,包括上面的#if:
#if defined __USE_MISC || defined __USE_BSD || defined __USE_XOPEN_EXTENDED
extern int mknod (const char *__path, __mode_t __mode, __dev_t __dev)
__THROW __nonnull ((1));
这是我在文件中包含的内容:
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <pthread.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
#include <bluetooth/rfcomm.h>
//#include <linux/stat.h>
程序尝试在此处创建管道:
umask(0);
fifo = mknod(PIPE_LOC, S_IFIFO|0666, 0);
fp = fopen(PIPE_LOC, "w");
fifo 是一个int,在其他任何地方都没有使用,fp 是一个FILE* 到管道。我所做的一些调试表明,fifo 在运行mknod 后的值为-1,可能是因为编译器似乎无法找到该函数的实现。
如何让 GCC 知道在哪里可以找到 mknod 的实现?
【问题讨论】:
-
一种更便携的创建命名管道的方法是
mkfifo函数,它是POSIX。
标签: c linux named-pipes raspbian mknod