Compiling programs with VS2008 and boost under windows

Source: Internet
Author: User

Original works, allow reprint, please be sure to use hyperlinks in the form of the original source of the article, author information and this statement. Otherwise, the legal liability will be investigated. http://co63oc.blog.51cto.com/904636/504469

Compiling programs with VS2008 and boost under windows
vc6.0 and boost combine many errors

Use the sample program for an HTTP server in the ASIO sub-Library, and the code is in the Libs\asio\example\http\server directory.

1. Download the Boost source file
http://sourceforge.net/projects/boost/files/boost/1.46.0/
2. Download the Boost compilation management tool Bjam, which invokes the system-installed compiler to compile the source program
Http://sourceforge.net/projects/boost/files/boost-jam/3.1.18/boost-jam-3.1.18-1-ntx86.zip
3. Assuming that the boost compression file is unzipped to F:\boost,boost-jam to F:\boost-jam
Open a command prompt,
F:
CD F:\boost
F:\boost-jam\bjam.exe Install
This will compile and install the Boost library to C:\boost
4. Open menu tools->options->projects and solutions->vc++ directories in vs2008
Add C:\Boost\include to include files
Add C:\Boost\lib to library files

5. New vs. MFC Application project Mfc2008_boost1,
Using the Release configuration
Project->project properties...->configuration properties->c/c++->precompiled Headers set Create/use The precompiled header is not using the precompiled Headers, that is, the precompiled header is not used, or the Compile Boost sample program has a precompiled error.
6. Copy all HPP, CPP files to project code directory under Libs\asio\example\http\server in boost source
7. Edit Mfc2008_boost1dlg.cpp.
This is the added code that is copied from the Win_main.cpp.
#include "stdafx.h"

#include <iostream>
#include <string>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include "server.hpp"

#include "Mfc2008_boost1.h"
#include "Mfc2008_boost1dlg.h"

Add a thread function to the Cmfc2008_boost1dlg class:
unsigned int cmfc2008_boost1dlg::thread1 (LPVOID param)
To add and modify code:
Boost::function0<void> console_ctrl_function;

BOOL WINAPI Console_ctrl_handler (DWORD ctrl_type)
{
Switch (ctrl_type)
{
Case Ctrl_c_event:
Case Ctrl_break_event:
Case Ctrl_close_event:
Case Ctrl_shutdown_event:
Console_ctrl_function ();
return TRUE;
Default
return FALSE;
}
}

unsigned int cmfc2008_boost1dlg::thread1 (LPVOID param)
{
Try
{
Initialise server.
Http::server::server s ("localhost", "n", "f:\\"); Local 88 port Listener, Access root directory is f:\

Set Console control handler to allow server to is stopped.
Console_ctrl_function = Boost::bind (&http::server::server::stop, &s);
SetConsoleCtrlHandler (Console_ctrl_handler, TRUE);

Run the server until stopped.
S.run ();
}
catch (std::exception& e)
{
Std::cerr << "Exception:" << e.what () << "\ n";
}

return 0;
}
8. Add thread creation code in OnInitDialog:
AfxBeginThread (Thread1, NULL);
9. Delete Win_main.cpp
10. Press F7 to compile the project. Ctrl+f5 Run
11. The browser opens http://localhost:88/, and a 404 error message appears, indicating that the service has been started. Input http://localhost:88/+ "f:\ The following file name is accessible.

Compiling boost takes a long time, and there's a website that makes a compiled boost library, www.boostpro.com
Download the installer and follow the prompts to select the compilation environment and the required library installation.

Compiling programs with VS2008 and boost under windows

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.