我不是基於命令行編譯的專業版。我從boost official example開發了以下的asio UDP應用程序。如何在/ usr/local編譯時使用clang ++進行鏈接?
// udpServer.cpp
#include <boost/asio.hpp>
#include <iostream>
#include <array>
using boost::asio::ip::udp;
int main()
{
try
{
boost::asio::io_service io_service;
udp::socket socket(io_service, udp::endpoint(udp::v4(), 13));
for (;;)
{
std::array<char, 1> recv_buf;
udp::endpoint remote_endpoint;
boost::system::error_code error;
socket.receive_from(boost::asio::buffer(recv_buf), remote_endpoint, 0, error);
if (error && error != boost::asio::error::message_size)
throw boost::system::system_error(error);
std::string message = "some_string";
boost::system::error_code ignored_error;
socket.send_to(boost::asio::buffer(message), remote_endpoint, 0, ignored_error);
}
}
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
}
return 0;
}
我使用Macports安裝了1.59,因爲這是我在做的版本sudo port install boost
。我看到,升壓位於我/usr/local/lib
&頭在/usr/local/include
我試圖從其他討論的建議,但代碼不編譯,因爲它是不能夠鏈接到提高。我在OSX &試圖編譯鏗鏘用下面的命令
clang++ -std=c++14 udpServer.cpp
試過這種
clang++ -std=c++14 -I /usr/local/include/boost -L /usr/local/lib udpServer.cpp
但得到以下錯誤:
Undefined symbols for architecture x86_64:
"boost::system::system_category()", referenced from:
boost::asio::error::get_system_category() in udpServer-4b9a12.o
boost::system::error_code::error_code() in udpServer-4b9a12.o
___cxx_global_var_init.2 in udpServer-4b9a12.o
"boost::system::generic_category()", referenced from:
___cxx_global_var_init in udpServer-4b9a12.o
___cxx_global_var_init.1 in udpServer-4b9a12.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
爲什麼不使用'自制'? – merito