4

I am working on a very simple file system for learning purposes, which uses fuse. However, I cannot compile it:

$ gcc -Wall `pkg-config fuse --cflags --libs` myfs.c -o myfs
/tmp/cc6xhGKO.o: In function `main':
myfs.c:(.text+0x1602): undefined reference to `fuse_opt_add_arg'
myfs.c:(.text+0x164f): undefined reference to `fuse_main_real'
collect2: ld returned 1 exit status

pkg-config already appends -lfuse (see below).

My system infos:

$ uname -a
Linux fpti 3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
$ dpkg -l | grep fuse
ii  fuse                            2.8.6-2ubuntu2             Filesystem in Userspace
ii  libfuse-dev                     2.8.6-2ubuntu2             Filesystem in Userspace (development)
ii  libfuse2                        2.8.6-2ubuntu2             Filesystem in Userspace (library)
$ pkg-config fuse --cflags --libs
-D_FILE_OFFSET_BITS=64 -I/usr/include/fuse  -pthread -lfuse -lrt -ldl
joni
  • 5,402
  • 1
  • 27
  • 40
  • I don't know if `pkg-config` is supposed to do this already, but try adding `-lfuse` to the end of your compile-command. – Kninnug Mar 09 '14 at 21:39
  • Sorry, forgot to mention this. See my edit. – joni Mar 09 '14 at 21:41
  • This is a shot in the dark, rather than a full SO answer. Depending on where fuse is installed, you need to make sure the compiler can find the header (.h) files, so you have function definitions. For compiling with gcc, I believe this will do the trick `gcc -I/path/to/directory/containing/header_name -o myoutputfile myoutputfile.c.`. -L points gcc to linking with libraries in a directory, and -l is used to link an explicit library. Hope this helps. – octopusgrabbus Mar 09 '14 at 22:00

1 Answers1

8

-l options need to be after the thing that needs them. The --libs output doesn't work because it's in the wrong place. Move it after myfs.c

  • 1
    haha, it works now: `gcc -Wall myfs.c 'pkg-config fuse --cflags --libs' -o myfs -o myfs` – joni Mar 10 '14 at 07:21