User forums > Using Code::Blocks

Boost.Asio Linking Help

<< < (2/3) > >>

Alpha:
Can you post your full build log?

JakeKazmier:


Uploaded with ImageShack.us
There you go.

JakeKazmier:
This is the coda, all of it. Is it possible that I am running only one part of the full example?
http://www.boost.org/doc/libs/1_49_0/doc/html/boost_asio/examples.html Chat example.


--- Code: ---//
// chat_message.hpp
// ~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff 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)
//

#ifndef CHAT_MESSAGE_HPP
#define CHAT_MESSAGE_HPP

#include <boost/asio.hpp>
#include <cstdio>
#include <cstdlib>
#include <cstring>

class chat_message
{
public:
  enum { header_length = 4 };
  enum { max_body_length = 512 };

  chat_message()
    : body_length_(0)
  {
  }

  const char* data() const
  {
    return data_;
  }

  char* data()
  {
    return data_;
  }

  size_t length() const
  {
    return header_length + body_length_;
  }

  const char* body() const
  {
    return data_ + header_length;
  }

  char* body()
  {
    return data_ + header_length;
  }

  size_t body_length() const
  {
    return body_length_;
  }

  void body_length(size_t new_length)
  {
    body_length_ = new_length;
    if (body_length_ > max_body_length)
      body_length_ = max_body_length;
  }

  bool decode_header()
  {
    using namespace std; // For strncat and atoi.
    char header[header_length + 1] = "";
    strncat(header, data_, header_length);
    body_length_ = atoi(header);
    if (body_length_ > max_body_length)
    {
      body_length_ = 0;
      return false;
    }
    return true;
  }

  void encode_header()
  {
    using namespace std; // For sprintf and memcpy.
    char header[header_length + 1] = "";
    sprintf(header, "%4d", body_length_);
    memcpy(data_, header, header_length);
  }

private:
  char data_[header_length + max_body_length];
  size_t body_length_;
};

#endif // CHAT_MESSAGE_HPP

--- End code ---

Alpha:
From what I can tell, you did not add the libraries previously mentioned to your linker.
The ones you need are system (most likely named something similar to boost_system-mgw44-mt-1_49) and ws2_32.
See here if you do not know how to add libraries.

For future reference, that is not a full build log.  A full build log would look something like this.  (See my previous link for how to enable full command line logging.)

--- Code: ----------------- Build: Release in Hello ---------------
mingw32-g++.exe -Wall -fexceptions -Os -c "C:\Documents and Settings\Alpha\My Documents\Programing\Hello\main.cpp" -o obj\Release\main.o
mingw32-g++.exe -o bin\Release\Hello.exe obj\Release\main.o -s
Output size is 7.00 KB
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings (0 minutes, 0 seconds)

--- End code ---

JakeKazmier:
So i added the "ws2_32" but in the i get an error saying that it cant find "boost_system-mgw44-mt-1_49". I found the dependencies but it did not list "ws2_32" any idea why? I know c++ but this is my first time working with boost or any 3rd party library for that matter, and I did quite some research on how to link libraries, but sorry if I seem clueless.
For future reference though, is there a file I should be looking for? And how do I know what version and numbers etc. to use in the linker code? One more thing... how do i know what i need for each specific library?
Thanks.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version