Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#9848 closed Bugs (fixed)

flyweight: hidden dependency on pthread

Reported by: akim@… Owned by: Joaquín M López Muñoz
Milestone: To Be Determined Component: flyweight
Version: Boost 1.55.0 Severity: Problem
Keywords: Cc:

Description

Hi,

My application does not link properly on ArchLinux (but out of the box on OS X and Ubuntu). For some reason, there I need -lpthread, and it appears that this requirement come from Flyweight. I could not find this dependency documented anywhere. Some clarification in the documentation would be most useful.

Thanks.

Change History (8)

comment:1 by Joaquín M López Muñoz, 9 years ago

Hi,

The dependency stems from the usage of boost::flyweights::simple_locking:

http://www.boost.org/libs/flyweight/doc/reference/locking.html#simple_locking

which takes advantage of the synchronization mechanisms available on the target environment. Your ArchLinux GCC distribution is configured in such a way that BOOST_HAS_PTHREADS is defined hence the need to link Pthreads with -lpthread. If you don't want to do the linking because your app is single-thread, you can either

  • use boost::flyweights::no_locking as the locking policy or
  • globally set the BOOST_DISABLE_THREADS macro.

Please report back whether this clarifies the issue for you. Best,

comment:2 by Joaquín M López Muñoz, 9 years ago

Resolution: invalid
Status: newclosed

comment:3 by akim@…, 9 years ago

Hi Joaquin,

Thanks for the quick response.

Actually, I already use no_locking in my project. Here is a small example:

[forge@prague tmp]$ cat foo.cc 
#include <boost/flyweight.hpp>
#include <boost/flyweight/no_tracking.hpp>

using string = boost::flyweight<std::string, boost::flyweights::no_tracking>;

int main()
{
  string h{"Hello, World!"};
}
[forge@prague tmp]$ clang++-3.4 -std=c++11 foo.cc 
/tmp/foo-856a4c.o:foo.cc:function boost::flyweights::detail::recursive_lightweight_mutex::recursive_lightweight_mutex(): error: undefined reference to 'pthread_mutexattr_init'
/tmp/foo-856a4c.o:foo.cc:function boost::flyweights::detail::recursive_lightweight_mutex::recursive_lightweight_mutex(): error: undefined reference to 'pthread_mutexattr_settype'
/tmp/foo-856a4c.o:foo.cc:function boost::flyweights::detail::recursive_lightweight_mutex::recursive_lightweight_mutex(): error: undefined reference to 'pthread_mutexattr_destroy'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Sure, it works with BOOST_DISABLE_THREADS, but then again, I have seen nothing about this in the documentation. A section on the dependencies would be helpful imho.

comment:4 by Joaquín M López Muñoz, 9 years ago

You're using no_tracking, not no_locking.

comment:5 by Akim Demaille <akim.demaille@…>, 9 years ago

Bwahaha! Thanks for pointing this out...

(But still, don't you think dependencies such as pthreads etc. should be mentioned in the documentation?)

comment:6 by Joaquín M López Muñoz, 9 years ago

Resolution: invalid
Status: closedreopened

comment:7 by Joaquín M López Muñoz, 9 years ago

Resolution: fixed
Status: reopenedclosed

comment:8 by akim@…, 9 years ago

Great! Thanks a lot for Flyweights!

Note: See TracTickets for help on using tickets.