Which library to link to user boost::intrusive_ptr - c++

is there possibility to find out which library file to link for libs that are using boost::intrusive_ptr?
I tried to use the boost bcp tool, but that does not give any hint in which dylib boost::intrusive_ptr is compiled.
On my system, I have these boost libs compiled (Version 1.49.0):
/usr/local/Cellar/boost/1.49.0/lib/
libboost_chrono-mt.a libboost_iostreams-mt.a libboost_math_c99l-mt.dylib libboost_program_options-mt.a libboost_serialization-mt.dylib libboost_timer-mt.dylib
libboost_chrono-mt.dylib libboost_iostreams-mt.dylib libboost_math_tr1-mt.a libboost_program_options-mt.dylib libboost_signals-mt.a libboost_unit_test_framework-mt.a
libboost_date_time-mt.a libboost_locale-mt.a libboost_math_tr1-mt.dylib libboost_python-mt.a libboost_signals-mt.dylib libboost_unit_test_framework-mt.dylib
libboost_date_time-mt.dylib libboost_locale-mt.dylib libboost_math_tr1f-mt.a libboost_python-mt.dylib libboost_system-mt.a libboost_wave-mt.a
libboost_exception-mt.a libboost_math_c99-mt.a libboost_math_tr1f-mt.dylib libboost_random-mt.a libboost_system-mt.dylib libboost_wave-mt.dylib
libboost_filesystem-mt.a libboost_math_c99-mt.dylib libboost_math_tr1l-mt.a libboost_random-mt.dylib libboost_test_exec_monitor-mt.a libboost_wserialization-mt.a
libboost_filesystem-mt.dylib libboost_math_c99f-mt.a libboost_math_tr1l-mt.dylib libboost_regex-mt.a libboost_thread-mt.a libboost_wserialization-mt.dylib
libboost_graph-mt.a libboost_math_c99f-mt.dylib libboost_prg_exec_monitor-mt.a libboost_regex-mt.dylib libboost_thread-mt.dylib
libboost_graph-mt.dylib libboost_math_c99l-mt.a libboost_prg_exec_monitor-mt.dylib libboost_serialization-mt.a libboost_timer-mt.a
The lib names themselves do not always give a hint to find the file to be linked (e.g boost::asio is in lboost_system-mt). Obviously it cannot be senseful to link randomly. Is there any way to find dependencies if I use anything from boost?
Best,
Sebastian

intrusive_ptr is a part of Smart Pointers library, which is header-only, i.e. you don't need to link anything.
Boost.Asio is not in lboost_system-mt, it just uses Boost.System (which is documented).

Related

Too many libboost_*.lib

I have downloaded boost 1.58.0 (precompiled, x86, VC 12.0) from http://boost.teeks99.com/ and installed to C:\local\boost_1_58_0 (I also tried compiled the source code using msvc-12.0 by myself and get the same result.
The problem: I see too many libboost*.lib of the same library, for example
ls -l libboost_math_* returns:
libboost_math_c99f-vc120-mt-1_58.lib
libboost_math_c99f-vc120-mt-gd-1_58.lib
libboost_math_c99f-vc120-mt-s-1_58.lib
libboost_math_c99f-vc120-mt-sgd-1_58.lib
libboost_math_c99f-vc120-s-1_58.lib
libboost_math_c99f-vc120-sgd-1_58.lib
libboost_math_c99l-vc120-mt-1_58.lib
libboost_math_c99l-vc120-mt-gd-1_58.lib
libboost_math_c99l-vc120-mt-s-1_58.lib
libboost_math_c99l-vc120-mt-sgd-1_58.lib
libboost_math_c99l-vc120-s-1_58.lib
libboost_math_c99l-vc120-sgd-1_58.lib
libboost_math_c99-vc120-mt-1_58.lib
libboost_math_c99-vc120-mt-gd-1_58.lib
libboost_math_c99-vc120-mt-s-1_58.lib
libboost_math_c99-vc120-mt-sgd-1_58.lib
libboost_math_c99-vc120-s-1_58.lib
libboost_math_c99-vc120-sgd-1_58.lib
libboost_math_tr1f-vc120-mt-1_58.lib
libboost_math_tr1f-vc120-mt-gd-1_58.lib
libboost_math_tr1f-vc120-mt-s-1_58.lib
libboost_math_tr1f-vc120-mt-sgd-1_58.lib
libboost_math_tr1f-vc120-s-1_58.lib
libboost_math_tr1f-vc120-sgd-1_58.lib
libboost_math_tr1l-vc120-mt-1_58.lib
libboost_math_tr1l-vc120-mt-gd-1_58.lib
libboost_math_tr1l-vc120-mt-s-1_58.lib
libboost_math_tr1l-vc120-mt-sgd-1_58.lib
libboost_math_tr1l-vc120-s-1_58.lib
libboost_math_tr1l-vc120-sgd-1_58.lib
libboost_math_tr1-vc120-mt-1_58.lib
libboost_math_tr1-vc120-mt-gd-1_58.lib
libboost_math_tr1-vc120-mt-s-1_58.lib
libboost_math_tr1-vc120-mt-sgd-1_58.lib
libboost_math_tr1-vc120-s-1_58.lib
libboost_math_tr1-vc120-sgd-1_58.lib
My questions:
Why are there so many lib files for one library? (36 files for
libboost_math, 4 libboost_atomic, 6 libboost_iostreams and so on)
Why are there no single libboost_math.lib, libboost_atomic, ...
files?
If I want to use boost_math, which library should I choose?
Boost.Math contains many parts, and they don't share the same library file.
The libraries' filename described what it builds for.
For example,
vc120: it builds for microsoft visual C++ 12.0 (a.k.a. 2013)
mt: will link with multithread version of C runtime. (libcmt.lib)
mt-s: will link with multithread version of shared C runtime. (msvcrt.lib)
mt-gd: will link with multithread debug version of C runtime. (libcmtd.lib)
mt-sgd: will link with multithread debug version of shared C runtime. (msvcrtd.lib)
s: will link with singlethread version of shared C runtime. (seems now VC doesn't contains one? I'm not sure.)
sgd: will link with singlethread debug version of shared C runtime. (seems now VC doesn't contains one? I'm not sure.)
If you are using Boost with Microsoft Visual C++, you will benefit from the auto-link feature. Set the additional library directory and the linker (to be exact, the boost header directs the linker) will link the correct version for you.

maps in shared memory: Boost.Interprocess demo fails due to unmet date_time dependency

I want to create shared map objects that multiple processes can access. The most promising approach I've found is this demo code from Boost.Interprocess, which allocates map objects in a managed shared memory segment. This question will mostly be about the boost problems I'm having, but I'd also be grateful if anyone has non-boost alternative approaches.
I'm completely new to boost: it looks amazing, if huge, and I was encouraged by its claim that "often, there's nothing to build". But in this case that promise is broken in what seems to be a senseless way, and I'm failing to compile the demo because of dependency problems internal to boost.
I'm on Windows, with Visual C++ Express 2010 installed. After saving the demo code as shmap.cpp I do the following:
"%VS100COMNTOOLS%\..\..\VC\vcvarsall.bat"
cl /EHsc /I boost_1_57_0 shmap.cpp
It compiles OK, but then I get this:
LINK : fatal error LNK1104: cannot open file 'libboost_date_time-vc100-mt-s-1_57.lib'
This surprises me on a number of levels. (Q1): I didn't ask for libraries---where and how is boost leading the linker to expect them? (Q2): Why would it be asking for date_time in particular? At no point in the code is anything as functionally specific as a date or time computed, referenced or included. Is this a case of overzealous blanket dependency, and if so is there a way I can weed it out?
Regardless, the obvious first thing to try was to play the game: in the boost_1_57_0 directory I ran bootstrap.bat followed by b2. The Earth turned a good few degrees, boost was built successfully, and I retried with:
cl /EHsc /I boost_1_57_0 shmap.cpp /link /LIBPATH:boost_1_57_0\stage\lib
I still get the same linker error. This is because b2 seems to have built libs with -mt- and with -mt-gd- in their names, but not with the -mt-s- that the linker is looking for. Boost's "Getting Started" webpage tells me what these stand for but doesn't tell me (Q3): how can I change either the type of library that gets built, or the type that the linker expects?
"At no point in the code is anything as functionally specific as a date or time computed, referenced or included."
(Q2): Why would it be asking for date_time in particular?
Apparently the things you used depend on it.
E.g the mutex operations have timed_lock function
(Q1): I didn't add libraries to the project---where and how is boost leading the linker to expect them?
Boost does autolinking by default. This uses MSVC++ specific pragmas to indicate the right flavour of the right link libraries. This is an awesome feature.
You just have to make sure the import libraries are on the library path for your project.
There are ways to disable auto-linking in boost (I think it involves defining BOOST_ALL_NO_LIB)
There might be ways to
disable dependency on boost date_time (dropping features); see the autl-link description in the Getting Started guide
linking to date_Time statically (or make it header-only)
I'd refer to the documentation for this.
Here's what I've learned, in large part thanks to sehe:
Q1: It's magic---specifically, MSVC-specific magic---and it happens because it's necessary.
Q2: It becomes unnecessary---i.e. the demo can be compiled without needing to look for a binary date_time lib---if I add /DBOOST_ALL_NO_LIB to the compile flags. But it's unclear whether that will still be true once I start to use additional IPC functionality like time-dependent mutexing.
Q3: Strings from the "Boost.Build option" column of this table can be passed to b2, so the way to create *-mt-s-*.lib is to say b2 runtime-link=static. This finally lets me compile without the /DBOOST_ALL_NO_LIB flag, and discover that date_time is the only library the demo seems to need.
I also discovered that the dependencies can be tracked with the bcp tool, and (eventually) also how to build bcp in the first place, as follows:
build:
cd boost_1_57_0
bjam tools\bcp
cd ..
report:
boost_1_57_0\dist\bin\bcp.exe --boost=boost_1_57_0 --report --scan shmap.cpp report.html
The result is that the maps-in-shared-memory demo needs 1421 files from boost 1.57.0.

gnat gprbuild : how to build a dynamic dll and link with a static c++ library

I have a full Ada project I want to build to get a dynamic dll.
Therefore I have to link it with another static library (myanotherlibrary.lib).
I use this command line :
gprbuild -d "D:\My_grp_project\My_grp_project.gpr"
Here the content of the .gpr :
project My_grp_project is
Architecture := "x86";
for Languages use ("Ada");
for Source_Dirs use (".", "source", "source\common");
for Library_Dir use "dll\" & Architecture;
for Library_Ali_Dir use "ali\" & Architecture;
for Library_Name use "My_grp_project";
for Library_Kind use "dynamic";
for Object_Dir use "obj\" & Architecture;
package Linker is
for Default_Switches ("Ada") use ("-L.", "-lbar");
end Linker;
end My_grp_project;
I put "myanotherlibrary.lib" in the directory "D:\My_grp_project\", but it still doesn't link: "undefined reference to ..."
Could anyone help me please ?
Regards
Glen
Looking at the docs, I think you should be using the Library_Options attribute instead of package Linker:
for Library_Options use ("-L.", "-lbar”);
(I’m confused - do you mean myanotherlibrary.lib or bar.lib?)
I’d be a bit concerned about using a static library from a dynamic library: I’d expect the dynamic library to be built with -fPIC or equivalent switch to get position-independent code, so that the same loaded library binary can be seen at different addresses in each of the executables using it.
Here the solution I finally found.
It is not possible to link static library compiled with MSVC. I had to compile my static library with GCC (same version as the one included in GNAT).
I had to add "Library_Options" options, without "-L" and "-l" arguments (another problem I passed). Note that package Linker is not taken into account while building a dynamic library. Note also that paths shall have no spaces !
project My_grp_project is
for Languages use ("Ada");
for Source_Dirs use (".", "source", "source\common");
for Library_Dir use “dll";
for Library_Ali_Dir use "ali";
for Object_Dir use "obj";
for Library_Name use "My_grp_project";
for Library_Kind use "dynamic";
for Library_Options use ("path\myanotherlibrary.a", "path_to_GNAT\libstdc++.a");
end My_grp_project;
I builded the project in the GPS (default option) : "Build All"
In result I do have my dynamic library "libMy_grp_project.dll"
Voilà.
Thanks !

Using Boost (Spirit) with g++ (and later Eclipse)

How can I configure g++ to use boost libraries? I Googled and tried many combinations but failed. I managed to get it working a few weeks ago ...
g++ test.cpp -o test -lboost
g++ test.cpp -o test -lboost_spirit
And afew with -I and -L flags ... but I always get
/usr/bin/ld: cannot find -lboost
collect2: error: ld returned 1 exit status
Am on Arch Linux. I will also like to know how to use Boost with Eclipse ... Looks like boost should have installed correctly?
[jiewmeng#JM-LAPTOP ~]$ ls /usr/include/boost/
accumulators move
algorithm mpi
aligned_storage.hpp mpi.hpp
any.hpp mpl
archive msm
array.hpp multi_array
asio multi_array.hpp
asio.hpp multi_index
assert.hpp multi_index_container.hpp
assign multi_index_container_fwd.hpp
assign.hpp next_prior.hpp
bimap non_type.hpp
bimap.hpp noncopyable.hpp
bind nondet_random.hpp
bind.hpp none.hpp
blank.hpp none_t.hpp
blank_fwd.hpp numeric
call_traits.hpp operators.hpp
cast.hpp optional
cerrno.hpp optional.hpp
checked_delete.hpp parameter
chrono parameter.hpp
chrono.hpp pending
circular_buffer phoenix
circular_buffer.hpp phoenix.hpp
circular_buffer_fwd.hpp pointee.hpp
compatibility pointer_cast.hpp
compressed_pair.hpp pointer_to_other.hpp
concept polygon
concept_archetype.hpp pool
concept_check preprocessor
concept_check.hpp preprocessor.hpp
config program_options
config.hpp program_options.hpp
container progress.hpp
crc.hpp property_map
cregex.hpp property_tree
cstdint.hpp proto
cstdlib.hpp ptr_container
current_function.hpp python
date_time python.hpp
date_time.hpp random
detail random.hpp
dynamic_bitset range
dynamic_bitset.hpp range.hpp
dynamic_bitset_fwd.hpp ratio
enable_shared_from_this.hpp ratio.hpp
exception rational.hpp
exception.hpp ref.hpp
exception_ptr.hpp regex
filesystem regex.h
filesystem.hpp regex.hpp
flyweight regex_fwd.hpp
flyweight.hpp scope_exit.hpp
foreach.hpp scoped_array.hpp
foreach_fwd.hpp scoped_ptr.hpp
format serialization
format.hpp shared_array.hpp
function shared_container_iterator.hpp
function.hpp shared_ptr.hpp
function_equal.hpp signal.hpp
function_output_iterator.hpp signals
function_types signals.hpp
functional signals2
functional.hpp signals2.hpp
fusion smart_ptr
generator_iterator.hpp smart_ptr.hpp
geometry spirit
geometry.hpp spirit.hpp
get_pointer.hpp statechart
gil static_assert.hpp
graph strong_typedef.hpp
heap swap.hpp
icl system
implicit_cast.hpp test
indirect_reference.hpp thread
integer thread.hpp
integer.hpp throw_exception.hpp
integer_fwd.hpp timer
integer_traits.hpp timer.hpp
interprocess token_functions.hpp
intrusive token_iterator.hpp
intrusive_ptr.hpp tokenizer.hpp
io tr1
io_fwd.hpp tuple
iostreams type.hpp
is_placeholder.hpp type_traits
iterator type_traits.hpp
iterator.hpp typeof
iterator_adaptors.hpp units
lambda unordered
last_value.hpp unordered_map.hpp
lexical_cast.hpp unordered_set.hpp
limits.hpp utility
local_function utility.hpp
local_function.hpp uuid
locale variant
locale.hpp variant.hpp
logic version.hpp
make_shared.hpp visit_each.hpp
math wave
math_fwd.hpp wave.hpp
mem_fn.hpp weak_ptr.hpp
memory_order.hpp xpressive
There is no boost library and there is no boost_spirit library to link against. Spirit is a header only library, you only need to set the include path to your boost installation. On a Linux system it is usually installed under /usr/include which is the default, so you don't even need to do that.
To get boost on Arch Linux:
pacman -S boost boost-libs
From Header-Only Libraries
The only Boost libraries that must be built separately are:
Boost.Filesystem
Boost.IOStreams
Boost.ProgramOptions
Boost.Python
(see the Boost.Python build documentation before building and
installing it)
Boost.Regex
Boost.Serialization
Boost.Signals
Boost.Thread
Boost.Wave
A few libraries have optional separately-compiled binaries:
Boost.DateTime has a binary component that is only needed if you're
using its to_string/from_string or serialization features, or if
you're targeting Visual C++ 6.x or Borland.
Boost.Graph also has a binary component that is only needed if you
intend to parse GraphViz files.
Boost.Test can be used in “header-only” or “separately compiled” mode,
although separate compilation is recommended for serious use.
You probably should set environment variable with path to includes needed.

Getting Chrono C++ library (Boost::sandbox) to work

i wanted to try out Chrono from the Boost sandbox. It seems to support a lot of stuff and should be stable.
I have Boost in version 1.44 installed on my system (incl. boost_system lib which is needed) and took the sandbox version (the download-version is older and misses for example the ratio.hpp file).
But it isn't compiling. Trying to compile the simple example from the documentation, with linking boost_system (in scons with LIBS=['boost_system']), the following error is occurring every time:
obj/main.o: In function `main':
/home/***/src/main.cpp:34: undefined reference to `boost::chrono::system_clock::now()'
scons: building terminated because of errors.
That seems to be a linker error. What did i do wrong? I have boost_system in version 1.44 linked (trough scons) and already tried the same with the older version 1.40.
Any tips? How did you setup your use of chrono?
Thanks.
sascha
Edit: This thread, which is talking about compatibility issues, let me think that the sandbox version of Chrono should be able to work with boost 1.44.
As described in the Installing Chrono documentation, you either need to build and link the Chrono library, or define BOOST_CHRONO_INLINED.
I had problems building Chrono from the trunk checkout, but it's probably related to the type_traits incompatibility mentioned in the Chrono docs.
I was able to build the example program with the following SConstruct (after fixing namespace errors):
env = Environment(
CPPDEFINES = ['BOOST_CHRONO_INLINED'],
CPPPATH = ['/.../boost_1_44_0', ],
LIBPATH = ['/.../boost_1_44_0/stage/lib', ],
LIBS = ['boost_system'],
)
env.Program('chrono-test', 'main.cpp')