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

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.

Related

BOOST_STATIC_WARNING in Xcode

I wish to include Boost into my Xcode project as per the example in Serialization - Tutorial.
I am using Boost version "1_60".
The project I am using is built using CMake.
set(Boost_USE_MULTITHREADED ON)
find_package(Boost REQUIRED COMPONENTS serialization system filesystem iostreams unit_test_framework date_time )
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIR})
target_include_directories(serialExample PRIVATE ${Boost_LIBRARY_DIR})
When I use the following includes...
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
"Unused typedef 'STATIC_WARNING_LINE102'"
"Unused typedef 'STATIC_WARNING_LINE98'"
"Unused typedef 'STATIC_WARNING_LINE137'"
"Unused typedef 'STATIC_WARNING_LINE148'"
This highlights four issues in two files which appear to be inside of the includes files.
extended_type_info_typeid.hpp
check.hpp
The code inspector goes to the error....
In file included from /opt/local/include/boost/archive/detail/interface_oarchive.hpp:23:
In file included from /opt/local/include/boost/archive/detail/oserializer.hpp:38:
/opt/local/include/boost/serialization/extended_type_info_typeid.hpp:102:9: error: unused typedef 'STATIC_WARNING_LINE102' [-Werror,-Wunused-local-typedef]
BOOST_STATIC_WARNING(boost::is_polymorphic< T >::value);
^
Is there a way to stop this? How do I suppress this type of warning?
Is this a Clang issue? Isn't Boost cross-platform?
Boost is error-free, but it does not purport itself as warning free. You are getting errors, because you told the compiler to treat warnings as errors (-Werror).
If you don't want to see Boost warnings, you can make sure that the compiler path to the headers is given by -isystem rather than -I, which will hide warnings from those headers. In CMake, this can be done by including the SYSTEM option in include_directories. See https://cmake.org/cmake/help/v3.0/command/include_directories.html.

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.

STLport error: '__cxa_demangle' is not a member of 'abi' for boost library

I have been trying to compile a piece of code which needs boost logging , things are fine when I try to compile with gnustl but when I switch to stlport the compiler, cribs loud with the following message.
In file included from /boost/include/boost/log/attributes/attribute_value.hpp:23:0,
from /boost/include/boost/log/attributes/attribute_value_set.hpp:27,
from /boost/include/boost/log/core/record.hpp:21,
from /boost/include/boost/log/core/core.hpp:23,
from /boost/include/boost/log/core.hpp:20,
from /boost/include/boost/log/common.hpp:22,
from /MyApp/FrameWorkLog.cpp:30:
/boost/include/boost/log/utility/type_info_wrapper.hpp: In member function 'std::string boost::log::v2s_mt_posix::type_info_wrapper::pretty_name() const':
/boost/include/boost/log/utility/type_info_wrapper.hpp:131:33: error: '__cxa_demangle' is not a member of 'abi'
I don't want to use gnustl for many reason.
More information:
The following is my Application.mk file configs
NDK_TOOLCHAIN_VERSION=4.6
APP_ABI := armeabi-v7a
APP_PLATFORM := android-14
APP_STL := stlport_static # For Static build
APP_CPPFLAGS := -frtti -fexceptions
Boost library version : 1.54.0
I tried building my app both 9c and 10b android ndk, but no difference.
/boost/include/boost/log/utility/type_info_wrapper.hpp:131:33: error: '__cxa_demangle' is not a member of 'abi'
Looking at the NDK's doc/CPLUSPLUS-SUPPORT.html, there's no mention of it. It looks like your have four choices.
First, you might be able to use Boost 1.56 because it appears type_info_wrapper.hpp does not use __cxa_demangle. I could be wrong, but I did not find it in the 1.56 header.
Second, configure Boost 1.54 such that BOOST_LOG_HAS_CXXABI_H is not defined. That will guard the use of abi::__cxa_demangle in 1.54's type_info_wrapper.hpp.
I don't know how to do it because I rarely use Boost, but I would probably hack it through config.hpp as follows. The Boost folks might know a bjam configuration option, so hopefully one of them will provide feedback.
// cxxabi.h availability macro
#if defined(BOOST_CLANG)
# if defined(__has_include) && __has_include(<cxxabi.h>)
# define BOOST_LOG_HAS_CXXABI_H
# endif
#elif defined(__GNUC__) && !defined(__QNX__)
# define BOOST_LOG_HAS_CXXABI_H
#endif
// Add these lines as a hack
#ifdef (__ANDROID__)
# undef BOOST_LOG_HAS_CXXABI_H
#endif
Third, try linking with one of the libraries that provide it. Unfortunately, it does not look like STLport provides it. It appears GAbi++ and GNU STL provide it:
$ cd /opt/android-ndk-r9/
$ find . -iname cxxabi.h
./sources/cxx-stl/gabi++/include/cxxabi.h
./sources/cxx-stl/gnu-libstdc++/4.4.3/include/cxxabi.h
./sources/cxx-stl/gnu-libstdc++/4.6/include/cxxabi.h
./sources/cxx-stl/gnu-libstdc++/4.7/include/cxxabi.h
./sources/cxx-stl/gnu-libstdc++/4.8/include/cxxabi.h
Fourth, port __cxa_demangle from one of the STL libraries that provide it. You can find the source code for the NDK libraries at Android Tools Project.

Which library to link to user boost::intrusive_ptr

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).

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')