我下载了c ++ boost 1_46_1。解压缩并遵循安装说明。
我试图获得一个基本的升级程序来编译和链接,但到目前为止没有运气。
这里是加速计划
#include <boost/program_options.hpp>
namespace po = boost::program_options;
#include <iostream>
#include <iterator>
using namespace std;
int main(int ac, char* av[])
{
try {
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("compression", po::value<int>(), "set compression level")
;
po::variables_map vm;
po::store(po::parse_command_line(ac, av, desc), vm);
po::notify(vm);
if (vm.count("help")) {
cout << desc << "\n";
return 1;
}
if (vm.count("compression")) {
cout << "Compression level was set to "
<< vm["compression"].as<int>() << ".\n";
} else {
cout << "Compression level was not set.\n";
}
}
catch(exception& e) {
cerr << "error: " << e.what() << "\n";
return 1;
}
catch(...) {
cerr << "Exception of unknown type!\n";
}
return 0;
}
这是我的makefile
# compiler to use
CC = c++
INC = -I ~/usr/local/boost_1_46_1
#-I /usr/include/c++/4.2.1
LIB=-L~/usr/local/boost_1_46_1/stage/lib
#LIB =-Lusr/local/lib
#LIBNAME =-libboost_program_options.dylib
SOURCE = main.cpp
OUTPUT = out
all:
$(CC) $(INC) $(SOURCE) -o $(OUTPUT) -v $(LIB) -dynamic
这是我得到的错误
Using built-in specs. Target: i686-apple-darwin10 Configured with: /var/tmp/gcc/gcc-5664~89/src/configure
--disable-checking --enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/
--with-slibdir=/usr/lib --build=i686-apple-darwin10 --program-prefix=i686-apple-darwin10- --host=x86_64-apple-darwin10 --target=i686-apple-darwin10 --with-gxx-include-dir=/include/c++/4.2.1 Thread model: posix gcc version 4.2.1 (Apple Inc. build 5664) /usr/libexec/gcc/i686-apple-darwin10/4.2.1/cc1plus
-quiet -v -I /Users/smith/usr/local/boost_1_46_1
-imultilib x86_64 -D__DYNAMIC__ main.cpp -fPIC -quiet -dumpbase main.cpp -mmacosx-version-min=10.6.6
-m64 -mtune=core2 -auxbase main -version -D__private_extern__=extern -o /var/folders/y7/y7wCKCc3HJWLBAK5YLrg5E+++TI/-Tmp-//ccumV5Oo.s ignoring nonexistent directory "/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../../../i686-apple-darwin10/include" ignoring nonexistent directory "/Users/smith/usr/local/boost_1_46_1"
#include "..." search starts here:
#include <...> search starts here: /usr/include/c++/4.2.1 /usr/include/c++/4.2.1/i686-apple-darwin10/x86_64 /usr/include/c++/4.2.1/backward /usr/local/include /usr/lib/gcc/i686-apple-darwin10/4.2.1/include /usr/include /System/Library/Frameworks (framework directory) /Library/Frameworks (framework directory) End of search list. GNU C++ version 4.2.1 (Apple Inc. build 5664) (i686-apple-darwin10) compiled by GNU C version 4.2.1 (Apple Inc. build 5664). GGC heuristics: --param ggc-min-expand=150
--param ggc-min-heapsize=131072 Compiler executable checksum: 35e7c8ac2c3562481c35a1833320fc34 /usr/libexec/gcc/i686-apple-darwin10/4.2.1/as
-arch x86_64 -force_cpusubtype_ALL -o /var/folders/y7/y7wCKCc3HJWLBAK5YLrg5E+++TI/-Tmp-//cce6AA55.o /var/folders/y7/y7wCKCc3HJWLBAK5YLrg5E+++TI/-Tmp-//ccumV5Oo.s /usr/libexec/gcc/i686-apple-darwin10/4.2.1/collect2
-dynamic -arch x86_64 -dynamic -macosx_version_min 10.6.6 -weak_reference_mismatches non-weak -o out -lcrt1.10.6.o
-L~/usr/local/boost_1_46_1/stage/lib -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/x86_64
-L/usr/lib/gcc/i686-apple-darwin10/4.2.1/x86_64
-L/usr/lib/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1
-L/usr/lib/gcc/i686-apple-darwin10/4.2.1
-L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../../i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../.. /var/folders/y7/y7wCKCc3HJWLBAK5YLrg5E+++TI/-Tmp-//cce6AA55.o
-lstdc++ -lSystem -lgcc -lSystem ld: warning: directory '~/usr/local/boost_1_46_1/stage/lib' following -L not found Undefined symbols: "boost::program_options::operator<<(std::basic_ostream<char, std::char_traits<char> >&, boost::program_options::options_description const&)", referenced from:
_main in cce6AA55.o "vtable for boost::program_options::variables_map", referenced from:
boost::program_options::variables_map::~variables_map()in cce6AA55.o "boost::program_options::detail::cmdline::set_additional_parser(boost::function1<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&>)", referenced from:
boost::program_options::basic_command_line_parser<char>::extra_parser(boost::function1<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&>)in cce6AA55.o "typeinfo for boost::program_options::validation_error", referenced from:
typeinfo for boost::exception_detail::error_info_injector<boost::program_options::validation_error>in cce6AA55.o
typeinfo for boost::program_options::invalid_option_valuein cce6AA55.o "boost::program_options::detail::cmdline::cmdline(std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)", referenced from:
boost::program_options::basic_command_line_parser<char>::basic_command_line_parser(int, char const* const*)in cce6AA55.o "boost::program_options::options_description_easy_init::operator()(char const*, char const*)", referenced from:
_main in cce6AA55.o "boost::program_options::value_semantic_codecvt_helper<char>::parse(boost::any&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool) const", referenced from:
vtable for boost::program_options::typed_value<int, char>in cce6AA55.o "boost::program_options::detail::cmdline::style(int)", referenced from:
boost::program_options::basic_command_line_parser<char>::style(int)in cce6AA55.o "boost::program_options::to_internal(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > boost::program_options::to_internal<std::basic_string<char, std::char_traits<char>, std::allocator<char> >
>(std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)in cce6AA55.o "boost::program_options::notify(boost::program_options::variables_map&)", referenced from:
_main in cce6AA55.o "boost::program_options::options_description_easy_init::operator()(char const*, boost::program_options::value_semantic const*, char const*)", referenced from:
_main in cce6AA55.o "boost::program_options::store(boost::program_options::basic_parsed_options<char> const&, boost::program_options::variables_map&, bool)", referenced from:
_main in cce6AA55.o "boost::program_options::arg", referenced from:
boost::program_options::typed_value<int, char>::name() constin cce6AA55.o
boost::program_options::typed_value<int, char>::name() constin cce6AA55.o "vtable for boost::program_options::value_semantic_codecvt_helper<char>", referenced from:
boost::program_options::value_semantic_codecvt_helper<char>::value_semantic_codecvt_helper()in cce6AA55.o
boost::program_options::value_semantic_codecvt_helper<char>::~value_semantic_codecvt_helper()in cce6AA55.o "typeinfo for boost::program_options::value_semantic_codecvt_helper<char>", referenced from:
typeinfo for boost::program_options::typed_value<int, char>in cce6AA55.o "boost::program_options::options_description::add_options()", referenced from:
_main in cce6AA55.o "boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
std::basic_string<char, std::char_traits<char>, std::allocator<char> > const& boost::program_options::validators::get_single_string<char>(std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool)in cce6AA55.o
std::basic_string<char, std::char_traits<char>, std::allocator<char> > const& boost::program_options::validators::get_single_string<char>(std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool)in cce6AA55.o "vtable for boost::program_options::validation_error", referenced from:
boost::program_options::validation_error::~validation_error()in cce6AA55.o
boost::program_options::validation_error::~validation_error()in cce6AA55.o
boost::program_options::validation_error::validation_error(boost::program_options::validation_error const&)in cce6AA55.o "boost::program_options::validation_error::what() const", referenced from:
vtable for boost::exception_detail::error_info_injector<boost::program_options::validation_error>in cce6AA55.o
vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::validation_error>
>in cce6AA55.o
vtable for boost::exception_detail::error_info_injector<boost::program_options::invalid_option_value>in cce6AA55.o
vtable for boost::program_options::invalid_option_valuein cce6AA55.o
vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::invalid_option_value>
>in cce6AA55.o "boost::program_options::variables_map::variables_map()", referenced from:
_main in cce6AA55.o "boost::program_options::options_description::options_description(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int, unsigned int)", referenced from:
_main in cce6AA55.o "boost::program_options::detail::cmdline::run()", referenced from:
boost::program_options::basic_command_line_parser<char>::run() in cce6AA55.o "boost::program_options::invalid_option_value::invalid_option_value(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
void boost::program_options::validate<int, char>(boost::any&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, int*, long)in cce6AA55.o "boost::program_options::options_description::m_default_line_length", referenced from:
_main in cce6AA55.o
_main in cce6AA55.o "boost::program_options::detail::cmdline::set_options_description(boost::program_options::options_description const&)", referenced from:
boost::program_options::basic_command_line_parser<char>::options(boost::program_options::options_description const&)in cce6AA55.o "boost::program_options::validators::check_first_occurrence(boost::any const&)", referenced from:
void boost::program_options::validate<int, char>(boost::any&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, int*, long)in cce6AA55.o "boost::program_options::abstract_variables_map::operator[](std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const", referenced from:
boost::program_options::variables_map::operator[](std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) constin cce6AA55.o ld: symbol(s) not found collect2: ld returned 1 exit status make: *** [all] Error 1
答案 0 :(得分:3)
你缺少-lboost_program_options
all:
$(CC) $(INC) $(SOURCE) -o $(OUTPUT) $(LIB) -lboost_program_options -dynamic
答案 1 :(得分:1)
您为链接器提供了错误的路径:
警告:目录'〜/ usr / local / boost_1_46_1 / stage / lib'跟踪-L未找到
导致无法关联您的对象
答案 2 :(得分:0)
链接器输出包括以下行:
ignoring nonexistent directory "/Users/smith/usr/local/boost_1_46_1"
因此,您期望库的位置与实际位置之间存在一些不匹配...