c++ - Boost Asio GCC Link Error -


i've installed clean vm xubuntu 12.10 , i'm trying port on c++ code works on windows. first off, i've installed virtualbox guest additions , gcc , can compile code.

i've downloaded boost library internet (boost_1_52) , i've dropped in asio library asio website (boost_asio_1_4_8) , i've installed multi-threading, shared link version using these instructions:

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

i know fact boost works because i've been able compile test application here (linking lboost_regex) , works perfectly:

#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;     } } 

so i'm trying build 1 of asio examples, i've built before no problems on windows. files here:

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

see:

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

i throw compiler this:

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

which gives me error:

connection.hpp:75:35: error: template argument 1 invalid connection.hpp:75:35: error: template argument 2 invalid connection.hpp:75:44: error: invalid type in declaration before ‘;’ token connection.hpp:76:13: error: request member ‘push_back’ in ‘buffers’, of non-class type ‘int’ connection.hpp:76:23: error: ‘asio’ not class or namespace connection.hpp:77:13: error: request member ‘push_back’ in ‘buffers’, of non-class type ‘int’ connection.hpp:77:23: error: ‘asio’ not class or namespace connection.hpp:78:5: error: ‘asio’ not class or namespace connection.hpp:78:23: error: ‘socket_’ not declared in scope connection.hpp: in member function ‘void s11n_example::connection::async_read(t&, handler)’: connection.hpp:87:15: error: ‘asio’ not name 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_’ not declared in scope connection.hpp:90:31: error: ‘asio’ has not been declared connection.hpp:91:21: error: ‘f’ not declared in scope connection.hpp:92:17: error: ‘asio’ has not been declared client.cpp: @ 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’ not name 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 ‘;’ @ end of member declaration client.cpp:43:47: error: iso c++ forbids declaration of ‘e’ no type [-fpermissive] client.cpp:43:47: error: expected ‘;’ @ end of member declaration client.cpp:43:48: error: expected unqualified-id before ‘)’ token client.cpp:125:1: error: expected ‘}’ @ end of input client.cpp:125:1: error: expected unqualified-id @ end of input client.cpp:125:1: error: expected ‘}’ @ end of input 

i'm confused, if i've not built boost or i'm missing link. i've tried linking winsock, no results. please help!

cheers

looks boost/asio.hpp didn't included correctly.

i don't remember prefix option does, think problem may somewhere in there. boost directory may not in /usr/include/boost, instead possibly /usr/boost.

that's 1 possibility. second that, instead of passing /usr/include/boost, need pass /usr/include, i.e.

gcc client.cpp -i /usr/include -lboost_system -lboost_thread -lboost_serialization  

if @ example files, e.g. connection.cpp example, includes boost/asio.hpp. boost/ part refers folder should looked compiler in include path(s) specify using -i. if specified /usr/include/boost, compiler going /usr/include/boost/boost/asio.hpp (notice 2 occurrences of boost).


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -