gpt4 book ai didi

c++ - Boost Asio GCC 链接错误

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:04:11 24 4
gpt4 key购买 nike

我刚刚用 xubuntu 12.10 安装了一个干净的虚拟机,我正在尝试移植一些在 Windows 上完美运行的 C++ 代码。首先,我已经安装了 Virtualbox guest additions 和 GCC,我可以编译代码。

我已经从互联网上下载了 boost 库 (boost_1_52),我已经从 asio 网站 (boost_asio_1_4_8) 下载了 asio 库,并且我已经使用这些说明安装了多线程、共享链接版本:

./bootstrap.sh --prefix=/usr &&
./b2 stage threading=multi link=shared

as root:

我知道 boost 有效,因为我已经能够在这里编译测试应用程序(与 lboost_regex 链接)并且它完美运行:

#include <boost/regex.hpp>
#include <iostream>
#include <string>

int main()
{
std::string line;
boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );

while (std::cin)
{
std::getline(std::cin, line);
boost::smatch matches;
if (boost::regex_match(line, matches, pat))
std::cout << matches[2] << std::endl;
}
}

因此,我正在尝试构建 ASIO 示例之一,我之前在 Windows 上构建时没有出现任何问题。文件在这里:

http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/examples.html

参见:

boost_asio/example/serialization/client.cpp
boost_asio/example/serialization/connection.hpp
boost_asio/example/serialization/server.cpp
boost_asio/example/serialization/stock.hpp

我把我的编译器扔成这样:

gcc client.cpp -I/usr/include/boost -lboost_system -lboost_thread -lboost_serialization

这给了我这个错误:

connection.hpp:75:35: error: template argument 1 is invalid
connection.hpp:75:35: error: template argument 2 is invalid
connection.hpp:75:44: error: invalid type in declaration before ‘;’ token
connection.hpp:76:13: error: request for member ‘push_back’ in ‘buffers’, which is of non-class type ‘int’
connection.hpp:76:23: error: ‘asio’ is not a class or namespace
connection.hpp:77:13: error: request for member ‘push_back’ in ‘buffers’, which is of non-class type ‘int’
connection.hpp:77:23: error: ‘asio’ is not a class or namespace
connection.hpp:78:5: error: ‘asio’ is not a class or namespace
connection.hpp:78:23: error: ‘socket_’ was not declared in this scope
connection.hpp: In member function ‘void s11n_example::connection::async_read(T&, Handler)’:
connection.hpp:87:15: error: ‘asio’ does not name a type
connection.hpp:87:31: error: expected unqualified-id before ‘&’ token
connection.hpp:87:31: error: expected ‘)’ before ‘&’ token
connection.hpp:87:31: error: expected initializer before ‘&’ token
connection.hpp:90:5: error: ‘asio’ has not been declared
connection.hpp:90:22: error: ‘socket_’ was not declared in this scope
connection.hpp:90:31: error: ‘asio’ has not been declared
connection.hpp:91:21: error: ‘f’ was not declared in this scope
connection.hpp:92:17: error: ‘asio’ has not been declared
client.cpp: At global scope:
client.cpp:26:10: error: ‘asio’ has not been declared
client.cpp:26:26: error: expected ‘)’ before ‘&’ token
client.cpp:43:29: error: ‘asio’ does not name a type
client.cpp:43:45: error: expected unqualified-id before ‘&’ token
client.cpp:43:45: error: expected ‘)’ before ‘&’ token
client.cpp:43:35: error: expected ‘;’ at end of member declaration
client.cpp:43:47: error: ISO C++ forbids declaration of ‘e’ with no type [-fpermissive]
client.cpp:43:47: error: expected ‘;’ at end of member declaration
client.cpp:43:48: error: expected unqualified-id before ‘)’ token
client.cpp:125:1: error: expected ‘}’ at end of input
client.cpp:125:1: error: expected unqualified-id at end of input
client.cpp:125:1: error: expected ‘}’ at end of input

我真的很困惑,就好像我没有建立 boost 或者我错过了另一个链接。我也试过与 Winsock 链接,但没有结果。请帮忙!

干杯

最佳答案

您正在交替使用 gcc 和 g++。不起作用的行使用 gcc,但有效的行使用 g++。使用 g++ 而不是 gcc 可能会影响使用哪个默认包含路径。您最初的错误不是链接。它正在编译。另外,如果你使用 boost 版本,asio 命名空间不是 asio。这是 boost::asio。

关于c++ - Boost Asio GCC 链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15825068/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com