我正在尝试在MacOS上使用Boost库。
我使用
我使用相同的命令
但是第一个程序编译成功,而第二个却没有。我该怎么办?
程序1.
当我编译程序2时,出现了以下错误。
我使用
brew install boost
安装了boost。这将boost安装在usr/local/Cellar/boost
中。我使用相同的命令
g++ --std=c++11 main.cpp -o main
编译了两个程序,然后运行./main
。但是第一个程序编译成功,而第二个却没有。我该怎么办?
程序1.
#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>
int main()
{
using namespace boost::lambda;
typedef std::istream_iterator<int> in;
std::for_each(
in(std::cin), in(), std::cout << (_1 * 3) << " " );
}
程序2。
#include <boost/test/unit_test.hpp>
int add( int i, int j ) { return i+j; }
BOOST_AUTO_TEST_CASE( my_test )
{
BOOST_CHECK( add( 2,2 ) == 4 );
BOOST_REQUIRE( add( 2,2 ) == 4 );
if( add( 2,2 ) != 4 )
BOOST_ERROR( "Ouch..." );
if( add( 2,2 ) != 4 )
BOOST_FAIL( "Ouch..." );
if( add( 2,2 ) != 4 ) throw "Ouch...";
BOOST_CHECK_MESSAGE( add( 2,2 ) == 4,
"add(..) result: " << add( 2,2 ) );
BOOST_CHECK_EQUAL( add( 2,2 ), 4 );
}
当我编译程序2时,出现了以下错误。
Undefined symbols for architecture x86_64:
"boost::test_tools::tt_detail::report_assertion(boost::test_tools::assertion_result const&, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstr
ing<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)", referenced from:
my_test::test_method() in del-9b4dcb.o
bool boost::test_tools::tt_detail::check_frwd<boost::test_tools::tt_detail::equal_impl_frwd, int, int>(boost::test_tools::tt_detail::equal_impl_frwd, boost
::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_det
ail::check_type, int const&, char const*, int const&, char const*) in del-9b4dcb.o
"boost::unit_test::unit_test_log_t::set_checkpoint(boost::unit_test::basic_cstring<char const>, unsigned long, boost::unit_test::basic_cstring<char const>)", r
eferenced from:
my_test_invoker() in del-9b4dcb.o
my_test::test_method() in del-9b4dcb.o
"boost::unit_test::test_case::test_case(boost::unit_test::basic_cstring<char const>, boost::unit_test::basic_cstring<char const>, unsigned long, boost::functio
n<void ()> const&)", referenced from:
boost::unit_test::make_test_case(boost::function<void ()> const&, boost::unit_test::basic_cstring<char const>, boost::unit_test::basic_cstring<char const>,
unsigned long) in del-9b4dcb.o
"boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::test_case*, boost::unit_test::decorator::collector&, unsigne
d long)", referenced from:
___cxx_global_var_init.1 in del-9b4dcb.o
"boost::unit_test::ut_detail::normalize_test_case_name(boost::unit_test::basic_cstring<char const>)", referenced from:
boost::unit_test::make_test_case(boost::function<void ()> const&, boost::unit_test::basic_cstring<char const>, boost::unit_test::basic_cstring<char const>,
unsigned long) in del-9b4dcb.o
"vtable for boost::unit_test::unit_test_log_t", referenced from:
boost::unit_test::unit_test_log_t::unit_test_log_t() in del-9b4dcb.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
g++ main.cpp -o main -I /usr/local/include -L /usr/local/lib -l boost-test
不起作用。它会出现一个错误ld: library not found for -lboost-test
。 - Harsh Kg++ main.cpp -o main -I/usr/local/include -L/usr/local/lib/ -libboost_test_exec_monitor.a
。仍然显示相同的错误。:( - Harsh K