C++: get Boost working; questions on include path and linking library -
i trying use boost.tokenizer library. in prog.cpp, have following:
#include <boost/tokenizer.hpp> and makefile like
cxx = g++-4.8 cxxflags = ## irrelevant flags ldflags = ## irrelevant flags sources = prog.cpp objects = $(sources:.cpp=.o) targets = prog $(targets) : $(objects) $(cxx) $(cxxflags) -o $@ $^ $(ldflags) ## other targets it won't compile, since boost/tokenizer.hpp cannot found:
fatal error: boost/tokenizer.hpp: no such file or directory then manually added boost include path cxxflags:
-i/opt/local/include/ (which path macports.)
then tried include tokenizer library, in /opt/local/lib/ have libboost_atomic-mt.dylib, libboost_chrono-mt.dylib, etc., nothing tokenizer. rather confused @ time. supposed still wouldn't work since library not linked against. surprisingly, program built, linked, , ran perfectly.
so i'm confused now. here questions:
(1) did not link against boost explicitly, boost treated standard library linker?
(2) if boost treated standard, why headers not standard?
(3) why there libboost_atomic-mt.dylib, libboost_chrono-mt.dylib, etc. not tokenizer? dynamic library tokenizer belong to?
i'm not familiar g++ linking mechanism; speaking of boost, first program boost. so i'd appreciate detailed explanation. in advance!
for reference, extracted gcc -print-search-dirs:
install: /usr/gcc-4.8.0/lib/gcc/x86_64-apple-darwin12.3.0/4.8.0/ programs: =/usr/gcc-4.8.0/libexec/gcc/x86_64-apple-darwin12.3.0/4.8.0/:/usr/gcc-4.8.0/libexec/gcc/x86_64-apple-darwin12.3.0/4.8.0/:/usr/gcc-4.8.0/libexec/gcc/x86_64-apple-darwin12.3.0/:/usr/gcc-4.8.0/lib/gcc/x86_64-apple-darwin12.3.0/4.8.0/:/usr/gcc-4.8.0/lib/gcc/x86_64-apple-darwin12.3.0/:/usr/gcc-4.8.0/lib/gcc/x86_64-apple-darwin12.3.0/4.8.0/../../../../x86_64-apple-darwin12.3.0/bin/x86_64-apple-darwin12.3.0/4.8.0/:/usr/gcc-4.8.0/lib/gcc/x86_64-apple-darwin12.3.0/4.8.0/../../../../x86_64-apple-darwin12.3.0/bin/ libraries: =/usr/gcc-4.8.0/lib/gcc/x86_64-apple-darwin12.3.0/4.8.0/:/usr/gcc-4.8.0/lib/gcc/x86_64-apple-darwin12.3.0/4.8.0/../../../../x86_64-apple-darwin12.3.0/lib/x86_64-apple-darwin12.3.0/4.8.0/:/usr/gcc-4.8.0/lib/gcc/x86_64-apple-darwin12.3.0/4.8.0/../../../../x86_64-apple-darwin12.3.0/lib/:/usr/gcc-4.8.0/lib/gcc/x86_64-apple-darwin12.3.0/4.8.0/../../../x86_64-apple-darwin12.3.0/4.8.0/:/usr/gcc-4.8.0/lib/gcc/x86_64-apple-darwin12.3.0/4.8.0/../../../:/lib/x86_64-apple-darwin12.3.0/4.8.0/:/lib/:/usr/lib/x86_64-apple-darwin12.3.0/4.8.0/:/usr/lib/
most of boost libraries, header files, if in .hpp files not see declaration of classes, expect in header file, entire implementation. why 90% of boost libraries, don't need worry linking, inclusion.
however few libraries, serialiser, few others, there polluting code header inclusion method reasonable. i'm sure there better, more rigid definition when implementation included in header , when isn't.
http://www.boost.org/boost-build2/doc/html/bbv2/faq/header-only-libraries.html
here question it: why not boost libraries header-only?
p.s. better keep boost library separate , in makefile like:
for compilation: cxxflags += -i/path/to/boost/include
for linking: ldpath += -l/path/to/boost/lib
this makes easier upgrade boost version have change path in 1 place.
Comments
Post a Comment