Building FUSE with g++

Fuse is a file system in user space that lets you implement your own file system without having root privileges. However, the documentation is very sparse so trudging through it has been an exercise in . All the given examples assume you're using the gcc compiler. If you try to build any of them with g++ / want to use C++, you should see this nice error:


g++ -Wall `pkg-config fuse --cflags --libs` hello.c -o hello // in the fuse/example/hello.c

hello.c: At global scope:
hello.c:87: error: expected primary-expression before ‘.’ token
hello.c:88: error: expected primary-expression before ‘.’ token
hello.c:89: error: expected primary-expression before ‘.’ token
hello.c:90: error: expected primary-expression before ‘.’ token

Let's take a look at the offending code:

   1:  static struct fuse_operations hello_oper = {
   2:    .getattr    = hello_getattr,
   3:    .readdir    = hello_readdir,
   4:    .open       = hello_open,
   5:    .read       = hello_read,
   6:  };

But using the compile command with gcc works great! What's going on? If you Google a bit, people say use the --std=c99 for C99 standards. That doesn't work. Essentially, g++ doesn't support "C struct member initialization". So how do you get around this!? Well you have to manually inherit from fuse_operations and write a constructor as such:

   1:  static struct hello_operations : fuse_operations {
   2:    fms_operations() {
   3:      getattr = hello_getattr;
   4:      read    = hello_read;
   5:      ...
   6:    }
   7:  } hello_oper_init;

Then g++ should be happy and you're good to go!

Other FUSE errors:
fuse_main not found! Make sure you insert the "#define FUSE_USE_VERSION 26" BEFORE you include <fuse.h>.

Permission Denied!?
This one is really weird. The OS user who starts the FUSE program is the only one who can read/write to the files UNLESS you edit /etc/fuse.conf to have the one line:


You can read about it at the Fuse wiki. It essentially lets other users read FUSE mounted folders. If you're still getting permission denied, make sure the permissions on /etc/fuse.conf are:

-rw-r--r-- 1 root fuse 215 2012-01-26 20:44 /etc/fuse.conf // owned by group fuse, chmod 644!

That should work.