0

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
4

2 回答 2

3

没有 boost 库,也没有要链接的 boost_spirit 库。Spirit 是一个只有头文件的库,你只需要设置你的 boost 安装的包含路径。在 Linux 系统上,它通常安装在/usr/include默认设置下,因此您甚至不需要这样做。

要在 Arch Linux 上获得提升:

pacman -S boost boost-libs
于 2013-01-12T14:28:17.757 回答
0

仅标题库

唯一必须单独构建的 Boost 库是:

Boost.文件系统

Boost.IOStreams

Boost.ProgramOptions

Boost.Python(在构建和安装之前请参阅 Boost.Python 构建文档)

升压正则表达式

Boost.序列化

升压信号

Boost.Thread

升压波

一些库具有可选的单独编译的二进制文件:

Boost.DateTime 有一个二进制组件,仅当您使用其 to_string/from_string 或序列化功能,或者您的目标是 Visual C++ 6.x 或 Borland 时才需要该组件。

Boost.Graph 还有一个二进制组件,仅当您打算解析 GraphViz 文件时才需要它。

Boost.Test 可以在“仅头文件”或“单独编译”模式下使用,但建议在严重使用时单独编译。

您可能应该将环境变量设置为包含所需的路径。

于 2013-01-12T15:25:55.723 回答