0

当我编译这个 helloworld 示例时,我得到以下错误重复 4 次:

error: expected primary-expression before ‘.’ token

这是代码:

static struct fuse_operations hello_oper = {
    .getattr    = hello_getattr,
    .readdir    = hello_readdir,
    .open   = hello_open,
    .read   = hello_read,
};

int main(int argc, char *argv[])
{
    return fuse_main(argc, argv, &hello_oper);
}
4

4 回答 4

1

你的编译器太旧了。它需要支持C99。如果编译器足够最新,则传入 -std=c99

于 2011-11-09T04:56:42.737 回答
0

该语法使用了C99 语言标准的一个新特性,称为指定初始值设定项。该功能不是更常见的 C89 标准(也称为 ANSI C)的一部分,因此当您尝试编译使用它的代码时,C89 编译器会给您语法错误。

要修复它,请告诉您的编译器使用它的 C99 模式(如果有的话)。例如,如果您使用 GCC,则应该传递-std=c99编译器选项。如果您的编译器根本不支持 C99,您将不得不切换到支持 C99 的编译器,或者重构代码以避免使用 C99 功能。

于 2011-11-09T05:39:59.610 回答
0

实际上,gcc支持较新的 C(或 C++)方言。尝试通过它gcc -std=c99 -Wall

于 2011-11-09T05:40:23.083 回答
0

遇到了类似的错误,尽管我无法通过添加“#define FUSE_USE_VERSION ...”来克服它,如上述评论之一所述。

为了克服这个错误,我在 fuse_operations 周围写了一个包装器,如下所示:

struct my_operations: public fuse_operations {
   my_operations()
   {
        read = my_read;
        open = my_open;
   }
} operations;

main(int argc, char* argv[])
{
  return fuse_main(argc, argv, &operations, NULL);
}
于 2017-09-23T08:51:28.470 回答