2013-01-12 15 views
0

如何配置g ++以使用boost庫?我谷歌搜索,並嘗試了很多組合,但失敗了。我設法得到它的工作在幾個星期前...使用Boost(Spirit)和g ++(以及後來的Eclipse)

g++ test.cpp -o test -lboost 
g++ test.cpp -o test -lboost_spirit 

並與-I和-L標誌AFEW ...但我總是對Arch Linux的

/usr/bin/ld: cannot find -lboost 
collect2: error: ld returned 1 exit status 

上午。我也想知道如何在Eclipse中使用Boost ...看起來boost應該已經正確安裝了?

[[email protected] ~]$ 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 

回答

3

沒有助推庫,也沒有boost_spirit庫來鏈接。 Spirit是僅包含頭文件的庫,您只需將包含路徑設置爲升級安裝。在Linux系統上,它通常安裝在/usr/include這是默認的,所以你甚至不需要那樣做。

要在Arch Linux的得到提升:

pacman -S boost boost-libs 
+0

我已經安裝了他們 –

+0

@JiewMeng那麼,你的問題是什麼? – pmr

+0

我仍然在'/ usr/bin/ld:找不到-lboost。 collect2:error:ld在編譯時返回1退出狀態,如在qn中所述 –

0

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.

你或許應該設置環境變量與路徑,包括必要的。