C 用户空间中的文件系统(FUSE)编译错误

C 用户空间中的文件系统(FUSE)编译错误,c,linux,compiler-errors,filesystems,userspace,C,Linux,Compiler Errors,Filesystems,Userspace,我还检查了fuse是否正确安装,因为头文件已包含在内,没有任何问题。但是为什么我不能编译这个简单的代码呢 有两种“fuse”版本,有时彼此共存:fuse2和fuse3。他们的看法不同。在我的Archlinux中有两个fuse包:fuse2和fuse3。在我的系统上,文件/usr/include/fuse.h仅包含fuse/fuse.h和fuse/fuse.h来自fuse2软件包。标题fuse3/fuse.h来自fuse3。 无论如何,您希望在这里使用fuse3 api,就像使用struct fu

我还检查了fuse是否正确安装,因为头文件已包含在内,没有任何问题。但是为什么我不能编译这个简单的代码呢

有两种“fuse”版本,有时彼此共存:fuse2和fuse3。他们的看法不同。在我的Archlinux中有两个fuse包:fuse2和fuse3。在我的系统上,文件
/usr/include/fuse.h
仅包含
fuse/fuse.h
fuse/fuse.h
来自fuse2软件包。标题
fuse3/fuse.h
来自fuse3。
无论如何,您希望在这里使用fuse3 api,就像使用
struct fuse\u config
一样。fuse3定义结构fuse\u配置
但是,首先,请在包含任何FUSE头文件之前定义FUSE_USE_VERSION宏,如中开头部分和中所述:

以下在我的平台上使用
gcc-Wall-pedantic-lfuse3 1.c
编译时没有警告/错误:

IMPORTANT: you should define FUSE_USE_VERSION before including this header.
#定义保险丝(使用)版本31
#包括
#包括
#包括
静态无效*pre_init(结构保险丝连接信息*conn,结构保险丝配置*cfg){
printf(“[init]调用\n”);
(无效)康涅狄格州;
返回NULL;
}
静态结构熔断器操作操作={
.init=pre_init,
};
int main(int argc,char*argv[]){
返回主保险丝(argc、argv和opr,空);
}

复制错误消息,使其可搜索。确保你已经使用错误信息搜索了,如果其他人已经解释了这个问题,考虑删除你的问题。@ UlrichEckhardt,因为我找不到一个可以理解的答案。我把它贴在了你的问题上,误解了:不要把图片链接到你的问题中去!请在问题中以文本形式引用错误!试试
#include
而不是
#include
@MarkPlotnick它似乎没有什么不同谢谢!但您能告诉我宏FUSE_USE版本的意义吗?它用于根据应用程序导出不同的FUSE api版本。根据其值,单个标头可能会导出不同的api。我不知道api之间的确切区别,您需要比较fuse api文档或查看更改。最好使用最新版本。看看类似的孤子,posix有posix_C_SOURCEOR,C11标准有STDC_WANT_LIB_EXT2。
 sample.c:7:59: warning: ‘struct fuse_config’ declared inside parameter list will not be visible outside of this definition or declaration
 static void* pre_init(struct fuse_conn_info *conn, struct fuse_config *cfg){
                                                           ^~~~~~~~~~~
 sample.c:12:15: error: variable ‘opr’ has initializer but incomplete type
 static struct fuse_operations opr = {
               ^~~~~~~~~~~~~~~
 sample.c:13:3: error: ‘struct fuse_operations’ has no member named ‘init’
  .init = pre_init,
   ^~~~
 sample.c:13:10: warning: excess elements in struct initializer
  .init = pre_init,
          ^~~~~~~~
 sample.c:13:10: note: (near initialization for ‘opr’)
 sample.c: In function ‘main’:
 sample.c:16:9: warning: implicit declaration of function ‘fuse_main’; did you mean ‘fuse_mount’? [-Wimplicit-function-declaration]
 return fuse_main(argc, argv, &opr, NULL);
         ^~~~~~~~~
         fuse_mount
 sample.c: At top level:
 sample.c:12:31: error: storage size of ‘opr’ isn’t known
 static struct fuse_operations opr = {
                               ^~~
IMPORTANT: you should define FUSE_USE_VERSION before including this header.
#define FUSE_USE_VERSION 31
#include <fuse3/fuse.h>
#include <stdio.h>
#include <stdlib.h>

static void* pre_init(struct fuse_conn_info *conn, struct fuse_config *cfg){
        printf("[init] called\n");
        (void) conn;
        return NULL;
}
static struct fuse_operations opr = {
        .init = pre_init,
};
int main(int argc, char *argv[]){
        return fuse_main(argc, argv, &opr, NULL);
}