我刚刚用xubuntu 12.10安装了一个干净的虚拟机,我试图移植一些在Windows上完美运行的C ++代码。首先,我已经安装了Virtualbox guest添加项和GCC,我可以编译代码。
我从互联网上下载了boost库(boost_1_52),我从asio网站(boost_asio_1_4_8)中删除了asio库,并使用这些说明安装了多线程共享链接版本:< / p>
./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
我真的很困惑,好像我没有建立提升或者我错过了另一个链接。我也试过与Winsock联系,没有结果。请帮忙!
干杯
答案 0 :(得分:0)
看起来boost/asio.hpp
没有被正确包含。</ p>
我不记得究竟是什么前缀选项,但我认为你的问题可能在那里的某个地方。 boost目录可能不在/usr/include/boost
中,而是可能在/usr/boost
。
这是一种可能性。第二个是,你需要传递/usr/include/boost
,而不是传递/usr/include
,而不是传递gcc client.cpp -I /usr/include -lboost_system -lboost_thread -lboost_serialization
。
boost/asio.hpp
如果查看示例文件,例如connection.cpp示例,它包含boost/
。 -I
部分指的是编译器应在您使用/usr/include/boost
指定的包含路径中查找的文件夹。因此,如果您指定/usr/include/boost/boost/asio.hpp
,编译器将查找boost
(注意{{1}}的两次出现。)
答案 1 :(得分:0)
我想我现在已经解决了这个问题。使用bjam和自动安装程序似乎没有做太多(由于某种原因它不会解析为这些路径)。
无论如何,我下载了ASIO源代码(这次非增强)并将其放在桌面上的目录中。与我在Visual Studio中的窗口上的方式类似,我设法将其链接到:
g++ client.cpp -I/home/devbox/desktop/asio-1.5.3/include - L/home/devbox/Desktop/boost_1_53_0/stage/lib -lboost_system -lboost_thread -lboost_serialization -o test
干杯全部
答案 2 :(得分:0)
您可以互换使用gcc和g ++。不起作用的行使用gcc,但工作的行使用g ++。使用g ++而不是gcc可能会影响使用哪个默认包含路径。您的初始错误未链接。它正在编译。此外,如果您使用boost版本,asio命名空间不是asio。它的提升:: asio。