Linker fails when compiling fuse files with "undefined reference to `fuse_main_real'

Bug #878612 reported by William Woelke
52
This bug affects 9 people
Affects Status Importance Assigned to Milestone
fuse (Ubuntu)
Invalid
Undecided
Dimitri John Ledkov
pkg-config (Ubuntu)
Invalid
Undecided
Dimitri John Ledkov

Bug Description

I had a working Fuse application when using Ubuntu 11.04, and I'm 99.9% sure I've
installed everything I need after re-installing Ubuntu 11.10.

I installed libfuse-dev and copied the
/usr/share/doc/libfuse-dev/examples/hello.c file to /tmp and ran the the command
listed at the top of the file:

gcc -Wall `pkg-config fuse --cflags --libs` hello.c -o hello

and it returns:

/tmp/ccYYt1z4.o: In function `main':
hello.c:(.text+0x33f): undefined reference to `fuse_main_real'
collect2: ld returned 1 exit status

libfuse-dev:
  Installed: 2.8.4-1.4ubuntu1
  Candidate: 2.8.4-1.4ubuntu1
  Version table:
 *** 2.8.4-1.4ubuntu1 0
        500 http://us.archive.ubuntu.com/ubuntu/ oneiric/main amd64 Packages
        100 /var/lib/dpkg/status

ProblemType: Bug
DistroRelease: Ubuntu 11.10
Package: libfuse-dev 2.8.4-1.4ubuntu1 [modified: usr/share/doc/libfuse-dev/changelog.Debian.gz]
ProcVersionSignature: Ubuntu 3.0.0-12.20-generic 3.0.4
Uname: Linux 3.0.0-12-generic x86_64
NonfreeKernelModules: nvidia
ApportVersion: 1.23-0ubuntu3
Architecture: amd64
Date: Wed Oct 19 19:00:51 2011
InstallationMedia: Ubuntu 11.10 "Oneiric Ocelot" - Beta amd64 (20111004)
SourcePackage: fuse
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
William Woelke (williamwoelke) wrote :
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in fuse (Ubuntu):
status: New → Confirmed
Revision history for this message
Jérôme DUMESNIL (jerome-dumesnil) wrote :

This bug only appears when using "fuse_main" macro.
When underlying functions (fuse_new, fuse_mount, ...) are directly called, the problem doesn't appear.

Revision history for this message
Jeremy Nickurak (nickurak) wrote :

Any workaround?

Revision history for this message
Flávio Martins (flavioxmartins) wrote :

This should work:

gcc -Wall -o hello hello.c `pkg-config fuse --cflags --libs`

The order of sources and libraries matters.
If you want to know more, you can read http://webpages.charter.net/ppluzhnikov/linker.html

Revision history for this message
Jeremy Nickurak (nickurak) wrote : Re: [Bug 878612] Re: Linker fails when compiling fuse files with "undefined reference to `fuse_main_real'

2011/12/1 Flávio Martins <email address hidden>:
> This should work:
>
> gcc -Wall  -o hello hello.c `pkg-config fuse --cflags --libs`

So what changed such that the libfuse-dev example Makefile has stopped
working correctly?

--
Jeremy Nickurak -= Email/XMPP: -= <email address hidden> =-

Revision history for this message
Henrik Ledin (henrik-ledin) wrote :

I think I have found what is causing this issue.
It seems to be something wrong with pkg-config, when used inside of the `` chars

When running `pkg-config fuse --cflags --libs` it returns
-D_FILE_OFFSET_BITS=64: command not found

Without the `` chars it returns
-D_FILE_OFFSET_BITS=64 -I/usr/include/fuse -pthread -lfuse -lrt -ldl

I'm not familiar with pkg-config, so I don't know how to fix this issue.

Best regards,
Henrik

Revision history for this message
Michał Wróbel (maw) wrote :

I corrected the Makefile by reordering LDFLAGS similarly to how Flávio Martins (xhaker) suggested, fixed installation of fioc.h header which was needed to build all the examples (including cusexmp, fioc, fioclient, fsel, fselclient) and uploaded the package to my PPA (at the time of writing, pending to be built): https://launchpad.net/~maw/+archive/fixes

Revision history for this message
noon (fabrice-bauzac) wrote :

LDFLAGS is the variable for the linker flags.
Linker libs such as -lfuse should be put in the LDLIBS variable, not in LDFLAGS.

To solve the problem and simplify the Makefile at the same time:

In the Makefile, the LDFLAGS definition should be replaced with LDLIBS:

LDLIBS := $(shell pkg-config fuse --libs)

Also the 2-line fusexmp_fh section should be simplified with:

fusexml_fh: LDLIBS += -lulockmgr

(To make it even cleaner, there should be separate CFLAGS and CPPFLAGS pkg-config settings: --cflags-only-other and --cflags-only-I respectively)

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in pkg-config (Ubuntu):
status: New → Confirmed
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

pkg-config operates correct here. And fuse pkg-config (.pc) files are also correct. The makefile is broken and bad =) either use it as a bad example, and write better ones in your own projects (or e.g. use modern cmake / automake from scratch instead of hand writting bad makefiles).

If you wish to fix the example makefile, it's best to report this upstream.

Changed in pkg-config (Ubuntu):
status: Confirmed → Invalid
Changed in fuse (Ubuntu):
status: Confirmed → Invalid
assignee: nobody → Dimitri John Ledkov (xnox)
Changed in pkg-config (Ubuntu):
assignee: nobody → Dimitri John Ledkov (xnox)
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.