Installing boost on OpenBSD
is simple:
$ pkg_add boost
Write a simple test program:
#include <boost/asio.hpp>
#include <iostream>
int main()
{
boost::system::error_code ec{};
auto server_addr{boost::asio::ip::make_address("127.0.0.1", ec)};
if (ec.value())
{
std::cerr << "Failed to parse the IP address. Error code = "
<< ec.value() << ". Message: " << ec.message();
return ec.value();
}
boost::asio::ip::tcp::endpoint ep{server_addr, 3003};
return 0;
}
Compile it:
$ c++ client.cpp
/tmp/client-238877.o: In function `boost::asio::error::get_system_category()':
client.cpp:(.text._ZN5boost4asio5error19get_system_categoryEv[_ZN5boost4asio5error19get_system_categoryEv]+0x5): undefined reference to `boost::system::system_category()'
/tmp/client-238877.o: In function `boost::system::error_code::error_code()':
client.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC2Ev]+0x1b): undefined reference to `boost::system::system_category()'
/tmp/client-238877.o: In function `boost::system::error_category::std_category::equivalent(int, std::__1::error_condition const&) const':
client.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentEiRKNSt3__115error_conditionE[_ZNK5boost6system14error_category12std_category10equivalentEiRKNSt3__115error_conditionE]+0x129): undefined reference to `boost::system::generic_category()'
client.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentEiRKNSt3__115error_conditionE[_ZNK5boost6system14error_category12std_category10equivalentEiRKNSt3__115error_conditionE]+0x16a): undefined reference to `boost::system::generic_category()'
/tmp/client-238877.o: In function `boost::system::error_category::std_category::equivalent(std::__1::error_code const&, int) const':
client.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentERKNSt3__110error_codeEi[_ZNK5boost6system14error_category12std_category10equivalentERKNSt3__110error_codeEi]+0x137): undefined reference to `boost::system::generic_category()'
client.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentERKNSt3__110error_codeEi[_ZNK5boost6system14error_category12std_category10equivalentERKNSt3__110error_codeEi]+0x178): undefined reference to `boost::system::generic_category()'
client.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentERKNSt3__110error_codeEi[_ZNK5boost6system14error_category12std_category10equivalentERKNSt3__110error_codeEi]+0x2d2): undefined reference to `boost::system::generic_category()'
c++: error: linker command failed with exit code 1 (use -v to see invocation)
Whoops!, it means linker can’t find related library. boost
libraries are installed in /usr/local/lib
:
$ ls -lt /usr/local/lib/libboost*
-rw-r--r-- 1 root bin 2632774 Jul 2 05:58 /usr/local/lib/libboost_regex-mt.a
-rw-r--r-- 1 root bin 1398613 Jul 2 05:58 /usr/local/lib/libboost_regex-mt.so.8.0
-rw-r--r-- 1 root bin 2632774 Jul 2 05:58 /usr/local/lib/libboost_regex.a
-rw-r--r-- 1 root bin 1398613 Jul 2 05:58 /usr/local/lib/libboost_regex.so.8.0
-rw-r--r-- 1 root bin 994564 Jul 2 05:58 /usr/local/lib/libboost_serialization-mt.a
-rw-r--r-- 1 root bin 484918 Jul 2 05:58 /usr/local/lib/libboost_serialization-mt.so.8.0
-rw-r--r-- 1 root bin 994564 Jul 2 05:58 /usr/local/lib/libboost_serialization.a
-rw-r--r-- 1 root bin 484918 Jul 2 05:58 /usr/local/lib/libboost_serialization.so.8.0
-rw-r--r-- 1 root bin 260322 Jul 2 05:58 /usr/local/lib/libboost_signals-mt.a
-rw-r--r-- 1 root bin 154973 Jul 2 05:58 /usr/local/lib/libboost_signals-mt.so.8.0
-rw-r--r-- 1 root bin 260322 Jul 2 05:58 /usr/local/lib/libboost_signals.a
......
So I should specify boost_system
library during compilation:
$ c++ -L/usr/local/lib client.cpp -lboost_system
$
This time it works!