使用 Boost 库的 C++ 代码以退出值 -1 终止(这是什么意思?)
C++ code using Boost libraries terminated with exit value -1 (What does that mean?)
我正在尝试启动一个使用 boost 库连接到网络服务器的 cpp 代码 (echo.websocket.org)。我已成功编译代码,0 个错误和 0 个警告。
//
// Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See
accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/boostorg/beast
//
//------------------------------------------------------------------------
//
// Example: WebSocket client, synchronous
//
//------------------------------------------------------------------------
//[example_websocket_client
#include <boost/beast/core.hpp>
#include <boost/beast/websocket.hpp>
#include <boost/asio/connect.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <cstdlib>
#include <iostream>
#include <string>
namespace beast = boost::beast; // from <boost/beast.hpp>
namespace http = beast::http; // from <boost/beast/http.hpp>
namespace websocket = beast::websocket; // from
<boost/beast/websocket.hpp>
namespace net = boost::asio; // from <boost/asio.hpp>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
using namespace std;
// Sends a WebSocket message and prints the response
int main(int argc, char** argv)
{
cout <<"Reached "<< endl;
std::cout <<"Reached "<< argv[1] << std::endl;
std::cout <<"Reached "<< argv[2] << std::endl;
std::cout <<"Reached "<< argv[3] << std::endl;
try
{
// Check command line arguments.
if(argc != 4)
{
std::cerr <<
"Usage: websocket-client-sync <host> <port> <text>\n" <<
"Example:\n" <<
" websocket-client-sync echo.websocket.org 80 \"Hello, world!\"\n";
return EXIT_FAILURE;
}
auto const host = argv[1];
auto const port = argv[2];
auto const text = argv[3];
// The io_context is required for all I/O
net::io_context ioc;
// These objects perform our I/O
tcp::resolver resolver{ioc};
websocket::stream<tcp::socket> ws{ioc};
// Look up the domain name
auto const results = resolver.resolve(host, port);
// Make the connection on the IP address we get from a lookup
net::connect(ws.next_layer(), results.begin(), results.end());
// Perform the websocket handshake
ws.handshake(host, "/");
// Send the message
ws.write(net::buffer(std::string(text)));
// This buffer will hold the incoming message
beast::multi_buffer buffer;
// Read a message into our buffer
ws.read(buffer);
// Close the WebSocket connection
ws.close(websocket::close_code::normal);
// If we get here then the connection is closed gracefully
// The buffers() function helps print a ConstBufferSequence
std::cout << beast::buffers(buffer.data()) << std::endl;
}
catch(std::exception const& e)
{
std::cerr << "Error: " << e.what() << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
我在 main 的第一行添加了 cout,但即使是那些也没有在控制台上打印。我试过将它们排除在外,但结果仍然相同。我不确定 (exit value:-1) 是什么意思以及如何前进?
构建成功后的控制台输出:
19:03:28 **** Incremental Build of configuration Debug for project BoostWebSocket ****
make all
Building file: ../src/BoostWebSocket.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/lib/include -O0 -g3 -c -fmessage-length=0 -std=c++0x -fPIC -pthread -MMD -MP -MF"src/BoostWebSocket.d" -MT"src/BoostWebSocket.d" -o "src/BoostWebSocket.o" "../src/BoostWebSocket.cpp"
Finished building: ../src/BoostWebSocket.cpp
Building target: BoostWebSocket
Invoking: GCC C++ Linker
g++ -L/usr/lib -shared -Wl,-soname=libboost_system -pthread -o "BoostWebSocket" ./src/BoostWebSocket.o
Finished building target: BoostWebSocket 19:03:34 Build Finished. 0 errors, 0 warnings. (took 5s.963ms)
按下 运行 后的控制台输出为空白
(image attached)
这个问题的解决方案是链接
我不得不将 -soname=libboost_system
更改为 -lboost_system
我正在尝试启动一个使用 boost 库连接到网络服务器的 cpp 代码 (echo.websocket.org)。我已成功编译代码,0 个错误和 0 个警告。
//
// Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See
accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/boostorg/beast
//
//------------------------------------------------------------------------
//
// Example: WebSocket client, synchronous
//
//------------------------------------------------------------------------
//[example_websocket_client
#include <boost/beast/core.hpp>
#include <boost/beast/websocket.hpp>
#include <boost/asio/connect.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <cstdlib>
#include <iostream>
#include <string>
namespace beast = boost::beast; // from <boost/beast.hpp>
namespace http = beast::http; // from <boost/beast/http.hpp>
namespace websocket = beast::websocket; // from
<boost/beast/websocket.hpp>
namespace net = boost::asio; // from <boost/asio.hpp>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
using namespace std;
// Sends a WebSocket message and prints the response
int main(int argc, char** argv)
{
cout <<"Reached "<< endl;
std::cout <<"Reached "<< argv[1] << std::endl;
std::cout <<"Reached "<< argv[2] << std::endl;
std::cout <<"Reached "<< argv[3] << std::endl;
try
{
// Check command line arguments.
if(argc != 4)
{
std::cerr <<
"Usage: websocket-client-sync <host> <port> <text>\n" <<
"Example:\n" <<
" websocket-client-sync echo.websocket.org 80 \"Hello, world!\"\n";
return EXIT_FAILURE;
}
auto const host = argv[1];
auto const port = argv[2];
auto const text = argv[3];
// The io_context is required for all I/O
net::io_context ioc;
// These objects perform our I/O
tcp::resolver resolver{ioc};
websocket::stream<tcp::socket> ws{ioc};
// Look up the domain name
auto const results = resolver.resolve(host, port);
// Make the connection on the IP address we get from a lookup
net::connect(ws.next_layer(), results.begin(), results.end());
// Perform the websocket handshake
ws.handshake(host, "/");
// Send the message
ws.write(net::buffer(std::string(text)));
// This buffer will hold the incoming message
beast::multi_buffer buffer;
// Read a message into our buffer
ws.read(buffer);
// Close the WebSocket connection
ws.close(websocket::close_code::normal);
// If we get here then the connection is closed gracefully
// The buffers() function helps print a ConstBufferSequence
std::cout << beast::buffers(buffer.data()) << std::endl;
}
catch(std::exception const& e)
{
std::cerr << "Error: " << e.what() << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
我在 main 的第一行添加了 cout,但即使是那些也没有在控制台上打印。我试过将它们排除在外,但结果仍然相同。我不确定 (exit value:-1) 是什么意思以及如何前进?
构建成功后的控制台输出:
19:03:28 **** Incremental Build of configuration Debug for project BoostWebSocket **** make all Building file: ../src/BoostWebSocket.cpp Invoking: GCC C++ Compiler g++ -I/usr/local/lib/include -O0 -g3 -c -fmessage-length=0 -std=c++0x -fPIC -pthread -MMD -MP -MF"src/BoostWebSocket.d" -MT"src/BoostWebSocket.d" -o "src/BoostWebSocket.o" "../src/BoostWebSocket.cpp" Finished building: ../src/BoostWebSocket.cpp Building target: BoostWebSocket Invoking: GCC C++ Linker g++ -L/usr/lib -shared -Wl,-soname=libboost_system -pthread -o "BoostWebSocket" ./src/BoostWebSocket.o
Finished building target: BoostWebSocket 19:03:34 Build Finished. 0 errors, 0 warnings. (took 5s.963ms)
按下 运行 后的控制台输出为空白 (image attached)
这个问题的解决方案是链接
我不得不将 -soname=libboost_system
更改为 -lboost_system